Charca / bootbot

Facebook Messenger Bot Framework for Node.js
MIT License
974 stars 253 forks source link

Get responses from quickReplies #152

Open valdu02100 opened 5 years ago

valdu02100 commented 5 years ago

Hi,

I'm new user from Bootbot framework. I try to get answer from a quick_replies from answer. I didn't know how to get this. I start with bot.setGetStartedButton() and want to get answer from quickReplies like ''🏹 Je recherche quelqu\'un' and go to the const convo_find_sexe(). I search in documentation but doesn't find answer. Can you help me.

Thanks

` 'use strict'; const BootBot = require('bootbot');

const bot = new BootBot({ accessToken: '...', verifyToken: '...', appSecret: '...' });

const new_tickets = (payload, chat) => { const message = Nouveaux Tickets!; const options = { typing: true }; chat.say(message, options); };

const convo_find_sexe = (convo) => { chat.say({ text: 'Pour commencer, était-ce une femme ou un homme', quickReplies: ['👩 Femme', '👨 Homme'] }); convo.set('find_sexe', payload.message.text); const answer = (payload, convo) => { if (!payload.message) { convo.end(); } const options = { typing: true }; }; };

const favoris = (payload, chat) => { const message = Vos favoris!; const otions = { typing: true }; chat.say(message, options); };

const tickets = (payload, chat) => { const message = Vos tickets!; const options = { typing: true }; chat.say(message, options); };

const faq = (payload, chat) => { const message = Vos questions!; const options = { typing: true }; chat.say(message, options); };

const settings = (payload, chat) => { const message = Vos paramètres!; const options = { typing: true }; chat.say(message, options); };

bot.setGetStartedButton((payload, chat) => { chat.getUserProfile().then((user) => { chat.say(👋 Salut ${user.first_name} ! Sais tu que les plus belles rencontres sont celles auxquelles on ne s\'attend pas? 💘, { typing: true }) .then(() => chat.say(Ces rencontres se font partout, mais surtout ailleurs ! 💕 Je suis là pour faciliter ces rencontres, { typing: true })) .then(() => chat.say({ text: 'Souhaites tu rechercher quelqu\'un ou lire les tickets ?', quickReplies: ['🔖 Lire les tickets', '🏹 Je recherche quelqu\'un', '⭐ Mes favoris', '💌 Mes tickets', '🤔 Comment ça fonctionne ?', '⚙️ Paramètres']}) ) }); });

`

danieldiner commented 5 years ago

I also had some trouble finding the answer to this. After you created your quick reply:

bot.hear(['Hola', 'hey', 'saludos', 'saludo', 'ong', 'Saludos', '¿Como estas?', 'quiero', 'quisiera','dónde', 'donde'], (payload, chat) =>{ const text = payload.message.text; console.log(text);

chat.say({
    text: 'Hi how may I help?',
    buttons: [
        {type: 'postback', title: 'Hours', payload: 'HOUR_SETTINGS'}, 
        {type: 'postback', title: 'Prices', payload: 'PRICES'},
        {type: 'postback', title: 'Talk to a human', payload: 'HELP_HUMAN'}
    ]   
});

});

You have to set up a listener to each of the events and set an action i.e

bot.on('postback:HELP_HUMAN', (payload, chat) => { console.log('The Help Me button was clicked!'); });

bot.on('postback:HOUR_SETTINGS', (payload, chat) => { console.log('The Hour button was clicked!'); });

bot.on('postback:PRICES', (payload, chat) => { console.log('The PRICES button was clicked!'); });

valdu02100 commented 5 years ago

In your exemple, you use buttons with postback but we can't use postback with quickReplies like buttons ? In more I want to send user to function when click on quickReplies without use bot.hear().

Thanks

danieldiner commented 5 years ago

You can try this code like that. I agree it is not the fanciest way but this works for quickReplies.

Because you are setting the button as a postback, so when you configure bot.hear() and pass trough the postback:paload I definitely catches the button clicked.

Why you don’t want to use bot.hear() ?

valdu02100 commented 5 years ago

so for you, I need to use :

const new_tickets = (payload, chat) => {
     const message = Nouveaux Tickets!; 
     const options = { typing: true };
     chat.say(message, options);
};

quickReplies: ['🔖 Lire les tickets', '🏹 Je recherche quelqu'un', '⭐ Mes favoris', '💌 Mes tickets', '🤔 Comment ça fonctionne ?', '⚙️ Paramètres']

bot.hear(['🔖 Lire les tickets'], (payload, chat) =>{
     const text = payload.message.text;
     console.log(text);
     chat.conversation(new_tickets);
});

It seems to be good for u ?

wfrancescons commented 5 years ago

Use .on(quick_reply:YOUR_PAYLOAD). Example:

chat.say({
        text: 'Some text',
        quickReplies: [{
            content_type: "text",
            title: "Option One",
            payload: "OPTION_ONE"
        }, {
                content_type: "text",
                title: "Option Two",
                payload: "OPTION_TWO"
            }], typing: 1000
    }

Then:

bot.on('quick_reply:OPTION_ONE', (payload, chat) => {
    //Do something
});
bot.on('quick_reply:OPTION_TWO', (payload, chat) => {
    //Do something
});
valdu02100 commented 5 years ago

@wfrancescons Thanks you, your answer resolved my problem. Thanks u ! 👍