-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Conversation does not work when require_delivery is true on express server #883
Comments
Hmm, investigating if this is an issue with the server code I supplied. Using just your index.js I am indeed able to reproduce this. @benbrown any idea what is going on here? After starting this convo, and responding to the first question, the bot is jumping straight to the next question, and then queueing the responses ( So far as I know that is unexpected behavior. UPDATE: Solution to your initial problem: cc @peterswimm cc @ouadie-lahdioui cc @colestrode cc @tylermachado anybody want to comment on creating dynamic conversations but avoiding this issue? I know I'm just missing something simple here... Update 2: |
I investigated further and found something of interest. It isn't actually issue with express. I tried to connect with botkit methods as found in messenger guide and I experience the same behavior. I checked my webhooks, seems ok: Also from @jonchurh answer it seems to be related to my newest issue |
@jonchurch just joined your slack team. Wanted to give more update. I do not understand how you managed to use sayFirst()? I really do not think that is it a valid solution because I am experiencing the same problem with say() and ask(). There is no askFirst() :) My code for conversation now:
I will not be so easy to reproducate it but the idea should be understandable. With this code either convo.say() or convo.ask() does not take any affect. Here is full log:
however if I comment out the last question (send us image) then the logic works fine. Another note - in both cases (with and without last question) the conversation never ends. I added
just before convo.activate() but nothing gets logged in console. here is botkit debug console (last question is coomented out): You can see that in debugs as well. After aswering last question bot get stuck on last question (I did couple of random strings there). |
I'm debugging this right now as well. Using facebook, but writing my code in Typescript. I have two handlers and while the first one works, the second one doesn't want to work My code export function listenToAll(controller: Controller) {
controller.on("message_received", messageReceivedCb);
controller.hears("add (.*) [d]rug", ["message_received"], addDrugCb);
}
export function messageReceivedCb(bot, message: BotkitFacebookMessage) {
if (message.text) {
bot.reply(message, `you said ${message.text}`);
}
}
export function addDrugCb(bot: Bot, message: BotkitFacebookMessage) {
bot.startConversation(message, (err, convo) => {
convo.ask(MSGS.TAKE_DRUG_OFFICIAL_NAME, (response, convo) => {
convo.say("cool I like that drug");
convo.next();
});
});
} EDIT realizing the code might seem odd xD it's for a drug adherence MVP, the convo.say response is because of a frustrated developer making his day a bit more fun :-P The top one works which calls this function worker.say = function(message, cb) {
botkit.middleware.send.run(worker, message, function(err, worker, message) {
if (err) {
botkit.log('Error in worker.say: ' + err);
} else {
worker.send(message, cb);
}
});
}; and my message gets delivered. But the conversation.ask calls this code this.addMessage = function(message, thread) {
if (!thread) {
thread = this.thread;
}
if (typeof(message) == 'string') {
message = {
text: message,
channel: this.source_message.channel,
};
} else {
message.channel = this.source_message.channel;
}
if (!this.threads[thread]) {
this.threads[thread] = [];
}
this.threads[thread].push(message);
// this is the current topic, so add it here as well
if (this.thread == thread) {
this.messages.push(message);
}
}; Which pushes the message into the this.messages array but the message never gets delivered. I assume this has something to do with botkit.tick = function() {
for (var t = 0; t < botkit.tasks.length; t++) {
botkit.tasks[t].tick();
}
for (var t = botkit.tasks.length - 1; t >= 0; t--) {
if (!botkit.tasks[t].isActive()) {
botkit.tasks.splice(t, 1);
}
}
this.trigger('tick', []);
}; or rather botkit.startTicking = function() {
if (!botkit.tickInterval) {
// set up a once a second tick to process messages
botkit.tickInterval = setInterval(function() {
botkit.tick();
}, 1500);
}
}; never actually ticking in my code. Looking into it, the |
Sure enough @KarlisJ @jonchurch // hook up facebook bot controllers
listenToAll(controller);
addAuthenticationMiddleware(controller);
controller.startTicking(); // <<< this one did it for me. |
@pascalwhoop we have It is 2 AM where I am so I really could not understand code in your first comment however after your second comment I went through Facebook.js file in botkit code and compared with our version. It really seems that we are doing everything as needed. I could only notice that we call |
I know it saturday but I am kind of out of time with this project so I wanted to update on issue :) Slept of the frustration, had a great breakfast and started everything from scratch. I started with botkit-starter-facebook bot and set it up (without botkit studio) and debuged from there. First of all - conversations does not get stuck. I was missing Secondly, What still holds true is the issue with order. From what I was able to debug the problems is that either
The order in conversation is:
|
It is inportant to me that I run my messenger bot on my own express server.
I have implemented botkit+express following this stackexchange answer by @jonchurch and it is working. I can receive and send back messages.
The problem (as for lot of developers as I can see) start when I create conversation. Consider this example:
I would expect the conversation like this:
but what I got was:
So I added
require_delivery: true
. However that breaks the conversation:I found a lot of issues when
require_delivery: true
breaks conversations. The latest resolve was pointing out that there is need to updatehandleWebhookPayload
function. I chencked the repository and found exact code that was suggested. After two days that leaves me out of options.Here is full code how I set up my bot with express server.
index.js:
express_webserver.js:
facebook-webhook.js:
facebook_setup.js:
and bot/index.js:
I will appreciate any help or guidence
The text was updated successfully, but these errors were encountered: