You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
I have a conversation that asks a series of questions, then takes those answers and performs a database query. I would like the results of that query to be presented as template elements such as in the example below. Does anyone know how I may be able to achieve this?
I am guessing it may be possible through convo.setVar but I'm not exactly sure how. Any help would be greatly appreciated!
controller.hears(['buy a shirt'], 'message_received', function(bot, message) {
bot.startConversation(message, function(err, convo) {
convo.ask({
attachment: {
'type': 'template',
'payload': {
'template_type': 'generic',
'elements': [
{
'title': 'Classic White T-Shirt',
'image_url': 'http://petersapparel.parseapp.com/img/item100-thumb.png',
'subtitle': 'Soft white cotton t-shirt is back in style',
'buttons': [
{
'type': 'web_url',
'url': 'https://petersapparel.parseapp.com/view_item?item_id=100',
'title': 'View Item'
},
{
'type': 'web_url',
'url': 'https://petersapparel.parseapp.com/buy_item?item_id=100',
'title': 'Buy Item'
},
{
'type': 'postback',
'title': 'Bookmark Item',
'payload': 'White T-Shirt'
}
]
},
{
'title': 'Classic Grey T-Shirt',
'image_url': 'http://petersapparel.parseapp.com/img/item101-thumb.png',
'subtitle': 'Soft gray cotton t-shirt is back in style',
'buttons': [
{
'type': 'web_url',
'url': 'https://petersapparel.parseapp.com/view_item?item_id=101',
'title': 'View Item'
},
{
'type': 'web_url',
'url': 'https://petersapparel.parseapp.com/buy_item?item_id=101',
'title': 'Buy Item'
},
{
'type': 'postback',
'title': 'Bookmark Item',
'payload': 'Grey T-Shirt'
}
]
}
]
}
}
}, function(response, convo) {
// whoa, I got the postback payload as a response to my convo.ask!
convo.next();
});
});
});
The text was updated successfully, but these errors were encountered:
Have you tried assigning (global) variables to your answers? That should do the trick.
If you get Answer 1 somewhere, you could set var url1, var title1 and var payload1, then use them appropriately.
Yeah I did try that however it doesn't work because convo messages are precompiled when convo.ask is first run, meaning that if you initialised your template elements collection array as an empty array, then that is what will be printed. Normally you would use convo.setVar to inject a variable set later, however that only works with strings.
Basically, you need a function to generate a new section of the conversation which you only call in the callback of the previous question. Thanks for taking the time to look at my problem though!
I have a conversation that asks a series of questions, then takes those answers and performs a database query. I would like the results of that query to be presented as template elements such as in the example below. Does anyone know how I may be able to achieve this?
I am guessing it may be possible through convo.setVar but I'm not exactly sure how. Any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: