How to capture the response from slack datepicker in Rasa NLU - datepicker

I am trying to create an interactive rasa chatbot with slack interface.
I have added datepicker to my slack bot from my actions.py file. However, I have no idea how to capture the selected date. I have used buttons and were able to capture the output using “value” field in the definition
msg = {
"blocks": [
{
"type": "section",
"block_id": "section1234",
"text": {
"type": "mrkdwn",
"text": "Pick a date for the deadline."
},
"accessory": {
"type": "datepicker",
"action_id": "datepicker123",
"initial_date": "2022-11-01",
"placeholder": {
"type": "plain_text",
"text": "Select a date"
}
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Process"
},
"value": "/custom_action",
"action_id": "actionId-0"
}
]
}
]
}
dispatcher.utter_message(json_message=msg)
When I press the button, the custom_action intent gets triggered. However, I need to set a deadline_date slot when the datepicker value is changed. I checked multiple tutorials, forms and docs but still do not have an idea how to accomplish that. Please help. Am using Rasa 3 community edition

Related

When creating a template in whatsapp cloud api it is always rejected

I am trying to create a template from postman by sending this object:
{
"name": "listado_productos",
"language": "es",
"category": "TRANSACTIONAL",
"components": [
{
"type" : "HEADER",
"format": "document",
"example": {
"header_handle": [
"https://drive.google.com/file/d/1CcTpDZL3p0ltMFhIKU9Vhz1LWG0bQFpN/view?usp=share_link"
]}
},
{
"type": "BODY",
"text": "Buenas tardes, acá le enviamos el nuevo listado de precios. Muchas gracias"
},
{
"type": "FOOTER",
"text": "ABS."
}
]
}
If I try an example from the official business-management-api guide, it also rejects it for non-compliance with terms and conditions.
"name": "promotional_message",
"language": "en_US",
"category": "TRANSACTIONAL",
"components": [{
"type":"BODY",
"text":"Hi {{1}}, get an extra 10% off every order above $300.",
"example":{"body_text":[["Sonia"]]}
},
{
"type":"HEADER",
"format":"TEXT",
"text": "Bonus Tuesday starts now!"
},
{
"type":"FOOTER",
"text":"Not interested? Tap Stop promotions"
},
{
"type":"BUTTONS",
"buttons":[{"type":"QUICK_REPLY", "text": "Shop now"},
{"type":"QUICK_REPLY", "text": "Stop promotions"}]
}]
The response is that it is rejected for being duplicate or not complying with WhatsApp Busiess Api terms and services but it is not true, I read the terms and conditions and the file / message format complies. Does anyone identify the problem?

The custom payload for the facebook messenger integration only shows up the first time it's called and not thereafter

I built a winebot that can suggest food pairings or make recommendations.
The integration with FB Messenger works fine, and it's supposed to call a carousel after a search to show you the various options. I found that when I call on it multiple times it will only display the carousel the first time and not a new one each time.
This is the function that calls the carousel
// CREATE RICH MESSAGES FOR FACEBOOK
function create_carousel(agent, carousel_params) {
agent.context.set({
name: 'carousel_output',
lifespan: 2,
parameters: carousel_params,
});
agent.setFollowupEvent('createCarousel');
agent.add(''); //add a dummy payload
return;
}
IntentMap is set up like this:
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('createCarousel', create_carousel);
agent.handleRequest(intentMap);
The createCarousel intent is set up with an event createCarousel and an output context called carousel_output
Under the messenger tab it has a text message followed by a payload. The text message and payload both use the content of carousel_output to make a recommendation.
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"elements": [
{
"image_url": "#carousel_output.product1.image",
"default_action": {
"url": "https://google.com",
"webview_height_ratio": "tall",
"type": "web_url"
},
"subtitle": "#carousel_output.product1.subtitle",
"title": "#carousel_output.product1.title",
"buttons": [
{
"url": "https://www.winemag.com/buying-guide/brovia-2013-garblet-sue-barolo/",
"title": "#carousel_output.product1.price",
"type": "web_url"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"image_url": "#carousel_output.product2.image",
"subtitle": "#carousel_output.product2.subtitle",
"default_action": {
"type": "web_url",
"webview_height_ratio": "tall",
"url": "https://google.com"
},
"title": "#carousel_output.product2.title",
"buttons": [
{
"type": "web_url",
"url": "https://www.wine-searcher.com/find/limerick+lane+cellars+rocky+knoll+zinfandel+russian+river+valley+sonoma+county+north+coast/2013",
"title": "#carousel_output.product2.price"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"default_action": {
"webview_height_ratio": "tall",
"type": "web_url",
"url": "https://google.com"
},
"image_url": "#carousel_output.product3.image",
"buttons": [
{
"title": "#carousel_output.product3.price",
"type": "web_url",
"url": "https://www.wine-searcher.com/find/charles+smith+k+vintner+the+hidden+sra+wahluke+slope+washington+usa/2009"
},
{
"title": "Some Text",
"type": "postback",
"payload": "Some Text"
}
],
"title": "#carousel_output.product3.title",
"subtitle": "#carousel_output.product3.subtitle"
}
],
"template_type": "generic"
}
}
}
}
What I noticed is that when I call the intent a second or third time , the message appears but the payload does not.
I 've already tried clearing output_context and deleting it but this does not seem to affect anything. I looked through the documentation of how payloads work but nothing specifically referencing the issue.
I was wondering if this may be a limitation on facebook messenger but don't see anything in the logs that is a flag. The function runs and the context is updated each time with the right content but just doesn't display in the bot.
The logs didn't show any errors, but the problem appeared in the data provided to the payload.
The code that creates the payload pulls images 3 at a time from a list of urls. There were only 5 urls provided in the list so on the second run it killed the carousel and did not show an undefined error message or a missing data error. Works fine after adding more urls to the list.

engati : Get button click value

Engati Chatbot question.
Engati tag is not exist yet so i manually add here.
I wanna try to get dynamic bank account number using custom code which shown as below
process({
"data": {
"type": "msg_options",
"text": "Choose an Account Number",
"options": [
{
"text": "12345678901234",
"postback": "flow_788224AF8006422BA5E587720DE3B252"
}, {
"text": "43210987654321",
"postback": "flow_788224AF8006422BA5E587720DE3B252"
}
]
}
});
Here in example i set two options and set same flow [flow_788224AF8006422BA5E587720DE3B252]
Now i want to get which option selected by user in flow_788224AF8006422BA5E587720DE3B252
Should i write any dynamic script for that or use any other options?
Resolved by below code
{
"data": {
"type": "msg_options",
"text": "Choose an option",
"options": [
{
"text": "12345678901234",
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=12345678901234"
}, {
"text": "43210987654321",
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=43210987654321"
}
]
}
}
Also you can user multiple variable like
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=43210987654321&data_bank=ICICI"
data_ is set to define attributes
and use in send message with {{account}}

Persistent menu not showing in Facebook Messenger chat bot

As I don't know why suggested, using Postman.
Per docs, have succesfully POSTed the configuration to facebook APIs:
which is not supposed to be anyways locale specific. Even I don't see here
Localization: Developers can now provide text in multiple languages (or entirely different menus) for each local your bot's users may come from.
Like my brother, I have tried almost everything so far
This looks like some crazy bug. Is there some work around to add a simplest persistent menu?
Wasted 2 hours on this issue. Until I realised you have to delete the conversation then refresh facebook with ignore cache (ctrl+shift+r in chrome) and then it will show.
The FB API document states that the API link to hit for applying persistent menu to the page specific bot is:
https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN>
Notice the me after version number i.e v2.6 in this specific case. However, this did not worked for a lot of people
There is small change in the API link to hit:
graph.facebook.com/v2.6/Page ID/messenger_profile?access_token=PAGE ACCESS TOKEN
Notice that me is replaced with the fb Page Id.
And the sample payload can still be the same:
{
"get_started": {
"payload": "Get started"
},
"persistent_menu": [
{
"locale": "default",
"composer_input_disabled": false,
"call_to_actions": [
{
"title": "Stop notifications",
"type": "nested",
"call_to_actions": [
{
"title": "For 1 week",
"type": "postback",
"payload": "For_1_week"
},
{
"title": "For 1 month",
"type": "postback",
"payload": "For_1_month"
},
{
"title": "For 1 year",
"type": "postback",
"payload": "For_1_year"
}
]
},
{
"title": "fresh jobs",
"type": "postback",
"payload": "fresh jobs"
},
{
"title": "More",
"type": "nested",
"call_to_actions": [
{
"title": "like us",
"type": "web_url",
"url": "https://www.facebook.com/nordible/"
},
{
"title": "blog",
"type": "web_url",
"url": "http://xameeramir.github.io/"
}
]
}
]
}
]
}
Notice that it is mandatory to configure get_started button before setting up the persistent_menu.

Facebook Messenger Bot - generic template default action not supporting messenger extensions

I am sending the bot the following data. The template is rendered properly, but Messenger Extensions only work when I use the Go button, but the default_action lacks support for Messenger Extensions and I get an error message saying that current version of the SDK doesn't support Messenger Extensions and that I should upgrade, but as stated above, using the Go button works well. How to get Messenger Extensions working with default action?
{
"recipient": {
"id": *recipientId*
},
"message": {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "*Title*",
"image_url": "*ImageUrl*",
"subtitle": "*Subtitle*",
"buttons": [
{
"type": "web_url",
"url": "*TheUrl*",
"title": "Go",
"messenger_extensions": true,
"fallback_url": "*TheUrl*"
},
{
"type": "element_share"
}
],
"default_action": {
"type": "web_url",
"url": "*TheUrl*",
"messenger_extensions": true,
"fallback_url": "*TheUrl*"
}
}
]
}
}
}
}