Botkit: Stopping a conversation immediately after saying something silences previous message

Created on 7 Mar 2016  路  12Comments  路  Source: howdyai/botkit

I run a conversation and in response to some answer either stop a conversation or call conversation.next. The code:

conversation.ask('Proceed?', (response, conversation) => {
  if (response.text === 'no') { // more comprehensive logic here; this sample is purely for this ticket.
    conversation.say('Okay');
    conversation.stop();
  } else {
    conversation.next();
  }
});

The conversation stops but I don't see the "Okay" message. Is this behavior correct?

Most helpful comment

My project is quite complicated and cannot be opensourced even partially, so the only thing I can do is create a separate project stub that shows how to use generators to hold stateful conversations. It's completely out of scope of this issue, but it works for me. You can check it out in taxigy/slackbot-starter.

The core points:

  • botkit is used as provider to Slack RTM API: I use its hears method to listen to all the messages from all the users,
  • generators are used as stateful conversations: since every generator is stateful, it is instantiated per every user, every channel.
  • no NLP, no data storage, but they should be to power up the bot's abilities to respond properly and hold context efficiently.
  • every message executes respond function that, in turn, picks next value from the generator; now it's up to you to construct generators to provide conversations, request information from the user and provide appropriate answers.
  • yield* with another generator branches the conversation to that generator from current point in conversation, without restarting anything, but there's no way back; it's impossible to finish branched conversation and jump back to the middle of the previous one (that would be awesome and that's what I'm working on).

I'll probably make a little live demo on a separate branch, but you're welcome to ask any questions, clone the repo and such.

All 12 comments

I believe you should use conversation.reply method for replying to a conversation instead of say.

You should not call conversation.stop, but rather conversation.next.

This will cause it to move on to the next message ("okay") and then end.

@anonrig, the problem is, conversation does not have reply property, so doing this way would cause a TypeError (there's however a bot instance in outer scope that does have reply property, I'll check it out).

@benbrown, I'm not getting this idea. I want the conversation to stop, why should I not call conversation.stop?

Conversations are queues.
They will continue until there are no messages left in the queue, OR, they end immediately when conversation.stop is called.

You do not need to call conversation.stop manually.

Okay, let me clarify. I'm having this code:

bot.startConversation(message, (error, conversation) => {
  conversation.ask('abc?', (response, conversation) => {
    if (response.text === 'no') {
      conversation.say('Okay'); // not working
      conversation.stop();
    } else {
      conversation.next();
    }
  });

  conversation.ask('def?', (response, conversation) => conversation.next());
});

So, if the user responds "no" for the question "abc?", the bot should say "Okay" and discontinue the conversation. In case the users doesn't respond "no", the bot should ask the next question, "def?", and wait for the user's response.

If I call conversation.then in the first ask, the conversation will unconditionally go to the next question (and all over questions that's been defined as async calls of conversation.ask);

So, once again, why is ask that is called along with stop not working?

Try this:

bot.startConversation(message, function (error, conversation)  {
  conversation.ask('abc?', function (response, conversation)  {
    if (response.text === 'no') {
      conversation.say('Okay'); // not working
      conversation.next();// this will move on the next conversation item in the queue. if there is none, it will end the conversation.
    } else {
      conversation.ask('def?', function(response, conversation) {
          //do something with user input
          conversation.next(); // this will move on the next conversation item in the queue. if there is none, it will end the conversation.
      });
    }
  }); 
});

That's a good suggestion, but I have already resolved this issue indirectly using ES6 generators and not using startConversation at all. Actually, I quite like the solution so I'd propose making a PR. If it turns into a general enough solution, I'll do it straightaway.

This is still an issue - I'm not sure why the issue is closed. If you have messages in a conversation queued, it's important to be able to stop the conversation properly...

The initial poster indicated the supplied responses fixed his issue. If you believe you've found a bug, or would like to submit a PR that addresses this, we'd be happy to review a new issue.

@taxigy : Can you post an exemple of your solution with ES6 generator ? Thanks !

@taxigy Would be great if you share your solution with us.

//cc @GautierT

My project is quite complicated and cannot be opensourced even partially, so the only thing I can do is create a separate project stub that shows how to use generators to hold stateful conversations. It's completely out of scope of this issue, but it works for me. You can check it out in taxigy/slackbot-starter.

The core points:

  • botkit is used as provider to Slack RTM API: I use its hears method to listen to all the messages from all the users,
  • generators are used as stateful conversations: since every generator is stateful, it is instantiated per every user, every channel.
  • no NLP, no data storage, but they should be to power up the bot's abilities to respond properly and hold context efficiently.
  • every message executes respond function that, in turn, picks next value from the generator; now it's up to you to construct generators to provide conversations, request information from the user and provide appropriate answers.
  • yield* with another generator branches the conversation to that generator from current point in conversation, without restarting anything, but there's no way back; it's impossible to finish branched conversation and jump back to the middle of the previous one (that would be awesome and that's what I'm working on).

I'll probably make a little live demo on a separate branch, but you're welcome to ask any questions, clone the repo and such.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

znat picture znat  路  4Comments

GautierT picture GautierT  路  3Comments

iworkforthem picture iworkforthem  路  3Comments

dfischer picture dfischer  路  4Comments

seriousssam picture seriousssam  路  3Comments