Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fixes #1932 - inserts a blank message after each prompt which allows …
Browse files Browse the repository at this point in the history
…the handlers to fire without interferring with the following message in the dialog
  • Loading branch information
benbrown committed Mar 13, 2020
1 parent db64e24 commit 59760d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/botkit/src/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class BotkitConversation<O extends object = {}> extends Dialog<O> {
* handler: async(response_text, convo, bot, full_message) => {
* return await convo.gotoThread('no_taco');
* }
* },s
* },
* {
* default: true,
* handler: async(response_text, convo, bot, full_message) => {
Expand Down Expand Up @@ -394,6 +394,9 @@ export class BotkitConversation<O extends object = {}> extends Dialog<O> {

this.script[thread_name].push(message);

// add a null message where the handlers for the previous message will fire.
this.script[thread_name].push({ action: 'next' });

return this;
}

Expand Down
19 changes: 13 additions & 6 deletions packages/botkit/tests/Dialog.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Botkit dialog', function() {
// botConvo.say('ok');

botConvo.ask({
text: ['what is your last name']
text: ['what is your last name{{vars.count}}']
}
, [
{
Expand All @@ -93,6 +93,13 @@ describe('Botkit dialog', function() {
handler: async (answer, convo, bot) => {
await bot.say('name not recognized, say another name');

let count = convo.vars.count;
if (!count) {
count = 1;
} else {
count++;
}
convo.setVar('count', count)/
await convo.repeat();
}
}
Expand Down Expand Up @@ -120,13 +127,13 @@ describe('Botkit dialog', function() {
assert(reply4.text === 'name not recognized, say another name', 'did not get invalid error 1');

const reply5 = await client.getNextReply();
assert(reply5.text === 'what is your last name', 'did not get reprompt');
assert(reply5.text === 'what is your last name1', 'did not get reprompt');

const reply6 = await client.sendActivity('brown');
assert(reply6.text === 'name not recognized, say another name', 'did not get invalid error 2');

const reply8 = await client.getNextReply();
assert(reply8.text === 'what is your last name', 'did not get reprompt');
assert(reply8.text === 'what is your last name2', 'did not get reprompt');

const reply9 = await client.sendActivity('smith');
assert(reply9.text === 'I like the name smith', 'did not get final confirm');
Expand Down Expand Up @@ -192,7 +199,7 @@ describe('Botkit dialog', function() {
assert(reply.text == 'ok', 'wrong reply');

const reply2 = await client.getNextReply();
assert(reply2.text == 'got it.', 'wrong reply 2');
assert(reply2.text == 'got it.', 'wrong reply 2 in addChildDialog test');
});

it('should work with call to addGotoDialog', async function() {
Expand Down Expand Up @@ -223,7 +230,7 @@ describe('Botkit dialog', function() {
assert(reply.text == 'ok', 'wrong reply');

const reply2 = await client.getNextReply();
assert(reply2 == null, 'wrong reply 2');
assert(reply2 == null, 'wrong reply 2 in addGotoDialog test');
});

it('should work with call to beginDialog in handler', async function() {
Expand Down Expand Up @@ -254,7 +261,7 @@ describe('Botkit dialog', function() {
assert(reply.text === 'ok you said black', 'wrong reply');

const reply2 = await client.getNextReply();
assert(reply2 === 'got it.', 'wrong reply 2');
assert(reply2.text === 'got it.', 'wrong reply 2 in beginDialog test');
});


Expand Down

0 comments on commit 59760d2

Please sign in to comment.