4
votes

I am developing a Chatbot using Microsoft Bot framework with nodejs, and I want to deploy this on aws lambda using serverless framework, but to do that, I need to call the lambda callback.

I cant find how I can have a callback when processing a message ends(saved data and sent all the necessary messages).

I tried to simulate the response, and call the callback, but it didnt work, microsoft bot framework continues processing the message, here is the current handler I have

'use strict';
const DynamoDbStorage = require('./dynamo-db-storage').DynamoDbStorage
let storage = new DynamoDbStorage()
const connector = require('./channel')(storage)

module.exports.message = (event, context, callback) => {
   connector.verifyBotFramework(context, getHandler(callback));
};

function getHandler(callback) {
   let status = 200
   return {
      status: (code) => { status = code },
      send: (data) => {
         const response = {
             statusCode: 200,
             body: JSON.stringify(data),
         };
         callback(null, response)
     }
   }
 }

And here is my channel.js

const builder = require('botbuilder');
function getChannel(storage) {

    const connector = new builder.ChatConnector({
        appId: process.env.MICROSOFT_APP_ID,
        appPassword: process.env.MICROSOFT_APP_PASSWORD
    });


    const bot = new builder.UniversalBot(connector, {
        storage: storage
    });

    //Bot logic
    //...

    return connector
}

module.exports = getChannel;
1
What does verifyBotFramework in ./channel do?doorstuck
It returns the Connector from botframework, and in that file I have the UniversalBot and all the logicCharles Stein

1 Answers

1
votes

The code you linked does not seem to call the send function on your res object. Have you tried adding an end() function to it that calls the callback function.

function getHandler(callback) {
    let status = 200
    return {
        status: (code) => { status = code },
        send: (data) => {
            const response = {
                statusCode: 200,
                body: JSON.stringify(data),
            };
            callback(null, response)
        },
        end: () => callback(null, "end called");
    }
 }