microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
683 stars 279 forks source link

Botbuilder doesn't respond after sending 'accepted' code when using cloud functions #375

Closed rwmb closed 6 years ago

rwmb commented 6 years ago

Botbuilder version: 3.15.0 I'm using Dialogflow as the handler for my botbuilder endpoint, which is a Azure Bot Service bot, and the handler is deployed on a Firebase Cloud Function, but for every botframework request I make, the function returns a 202 (that's the default behaviour of botbuilder I believe), and the function stops working in the middle of the code. I saw in this response from Frank van Puffelen that the functions may halt if there's a response from the function.
https://stackoverflow.com/questions/42875400/cloud-functions-for-firebase-serializing-promises

Is there a way to stop this "accepted" code from returning? I know the rest of the code is working fine because I'm using the same principles in my web version of the chatbot, so I'm certain that it's relalted to botbuilder's integration with firebase cloud functions. I'm using the Universal Bot to setup the callback for the messages. const bot = new builder.UniversalBot(this.connector, botFrameworkCallback) .set('storage', new builder.MemoryBotStorage());

And here's the botFrameworkCallback:

const botFrameworkCallback = (session) => {
  const message = session.message.text;
  const userRef = new UserRef('user');
  let userInfo;
  userRef
    .get()
    .then((userInformation) => {
      console.log('user information', userInformation);
      userInfo = userInformation;
      const userData: IUser = {
        ...userInfo,
        ref: userRef
      };
      return makeDialogflowRequest(userData, message);
    })
    .then((intentResult: any) => {
      console.log('intent result', intentResult);
      const response = intentResult.answer;
      session.send(response);
    })
    .catch((err) => {
      console.log('Error on BotFramework', err);
      const response = 'Sorry. An error happened while getting your response.';
      session.send(response);
    });
}

The whole integration part is there to give user specific responses, so this code does a lot of API requests, like Firestore ones, the Dialogflow one, and because of that we've set it up this way.

stevkan commented 6 years ago

The Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repo  is the preferred platform for submitting bug fixes and feature requests.


You have already asked the question in issue #5004 in the BotBuilder repo. My recommendation would be to continue to push Firebase to assist you.

EricDahlvang commented 6 years ago

@rwmb Have you tried to 'bubble up' the Promise, as Frank van Puffelen suggested?

rwmb commented 6 years ago

That doesn't work, the request sends a 202. Using cloud functions there's no way to respond to this request correctly. I had to create a pubsub topic and send the request to that in order to prevent the function from halting.