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

bot.startConversation is not a function #38

Open
AutomataVM opened this issue Sep 5, 2019 · 4 comments
Open

bot.startConversation is not a function #38

AutomataVM opened this issue Sep 5, 2019 · 4 comments

Comments

@AutomataVM
Copy link

I can't help but feel this readme/doc whatever is heavily outdated. I get the bot.startConversation is not a function message, so my best guess is that it was replaced by something else. Where can I get the latest updated docs available? the main page is a mess tbh.

@lenon461
Copy link

i have a same problem too

@invincibel
Copy link

facing the same issue

@Mattw11486
Copy link

I am also running into the same issue. Has anyone found a solution to this?

@Mattw11486
Copy link

FWIW I was able to get this working using this which works in creating a conversation. This is just a sample though I found from some github repo

` const ONBOARDING_PROMPT = 'onboarding_prompt';
const PROFILE_DIALOG = 'profile_dialog';
const ONBOARDING_DIALOG = 'onboarding_dialog';
const CONFIRM_DIALOG = 'confirm_dialog';
const START_OVER = 'start_over';

/**
 * Create a TextPrompt that will be used by the profile dialog
 */
const textPrompt = new TextPrompt(ONBOARDING_PROMPT);

/**
 * Define a simple waterfall dialog that collects profile information.
 */
const profile = new WaterfallDialog(PROFILE_DIALOG,[
    async(step) => {
        return await step.prompt(ONBOARDING_PROMPT, 'What is your name?');            
    },
    async(step) => {
        // capture result of previous step
        step.values.name = step.result;

        return await step.prompt(ONBOARDING_PROMPT, 'What is your age?');
    },
    async(step) => {
        // capture result of previous step
        step.values.age = step.result;

        return await step.prompt(ONBOARDING_PROMPT, 'What is your location?');
    },
    async(step) => {
        // capture result of previous step
        step.values.location = step.result;

        return await step.endDialog(step.values);
    }
]);

const confirmation = new BotkitConversation(CONFIRM_DIALOG, controller);
confirmation.say('Your name is {{vars.profile.name}}, your age is {{vars.profile.age}} and your location is {{vars.profile.location}}');
confirmation.ask('Is that correct?', [
    {
        pattern: 'no',
        handler: async(res, convo, bot) => {
            await convo.gotoThread('try_again');
            // convo
        }
    },
    {
        default: true,
        handler: async(res, convo, bot) => {
            // noop, just continue
        }
    }
],{key:'confirmed'});
confirmation.say('All done!');
confirmation.addGotoDialog(START_OVER,'try_again');

const startover = new BotkitConversation(START_OVER, controller);
startover.say('Lets start from the top...');
startover.addChildDialog(PROFILE_DIALOG, 'profile');
startover.addGotoDialog(CONFIRM_DIALOG);

/**
 * Now, define a BotkitConversation style dialog that will use the profile dialog as a child.
 */
const onboarding = new BotkitConversation(ONBOARDING_DIALOG, controller);
onboarding.say('Hello, human! Nice to meet you.');
onboarding.say('Before we begin, I need to ask you some questions.');
onboarding.addChildDialog(PROFILE_DIALOG, 'profile');
onboarding.say('Thanks, {{vars.profile.name}}! Your onboarding has completed.');
onboarding.addGotoDialog(CONFIRM_DIALOG);

/**
 * Add all of our dialogs to the bot.
 */
controller.addDialog(textPrompt);
controller.addDialog(profile);
controller.addDialog(onboarding);
controller.addDialog(confirmation);
controller.addDialog(startover);

/** 
 * When the profile dialog ends, store the info!
 */
controller.afterDialog(ONBOARDING_DIALOG, async(bot, results) => {

    if (results.confirmed != 'no') {
        console.log('PROFILE CAPTURED!', results);
        // do something like store this in the database.
    }
});

/**
 * listen for someone to say "onboarding" and fire the parent dialog!
 */
controller.hears('onboarding', 'message,direct_message', async(bot, message) => {
    await bot.beginDialog(ONBOARDING_DIALOG);
})    

`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants