I am trying to build a bot using Microsoft Bot Framework. I am planning to use a Azure Function with Http Trigger as the endpoint. NodeJS is the language of my choice. I am seeing botframework examples with restify and nodejs but none on using azure functions. Can anyone point me to an example where botframework is developed using azure functions and nodejs or give me an example on how to do it.
2 Answers
You can see here https://github.com/vjrantal/bot-sample/commit/e80faefded1c9da9a8b0d69e36497bb221b54709 a changeset that brings Azure Functions compatibility to a bot built with restify.
The approach is borrowed from Chris Anderson's project at https://github.com/christopheranderson/functions-bot-example but includes updates to work with the latest botbuilder.
UPDATE: On latest Functions runtime, you don't need the wrapping anymore. See https://github.com/vjrantal/bot-sample/commit/fe56a16f6f0286bfe66095eefc417388c1bc1e1c for details.
Comments
From Chris Anderson...
https://github.com/christopheranderson/functions-bot-example
You'll need to connect it to an HTTP trigger and the following code does the integration.
var listen = bot.listen();
var response = function (context) {
return {
send: function (status, message) {
var _msg = message ? message : (typeof status !== 'number' ? status : null)
var _status = typeof status === 'number' ? status : 200
var res = {
status: _status,
body: _msg
};
context.res = res;
context.done();
}
}
}
module.exports = function (context, req) {
listen(req, response(context))
}