Rasa version: Rasa 1.1.4
Python version: Python 3.6.8
Operating system (windows, osx, ...): Windows (host)
Issue:
Just to further clarify, I'm using Docker instance of the Rasa's image rasa/rasa:1.1.4-full. And I'm also using Rasa's implemented connector for Telegram. The Rasa raises the error when it tries to send request to the Telegram to display the buttons. I'm using custom implementation of the action_default_ask_affirmation function and not the default one. This implementation was taken from the rasa-demo (link to the implementation is https://github.com/RasaHQ/rasa-demo/blob/master/demo/actions.py#L445). The only change that I've made is that instead of calling:
dispatcher.utter_button_message(message_title, buttons=buttons)
I'm calling:
dispatcher.utter_button_message(message_title, buttons=buttons, button_type="vertical")
In most cases Rasa works perfectly well and the buttons are correctly displayed. But in some cases the following error occurs on the Rasa server (check the error's traceback below). Those cases are the similar as the one that works. They are similar in the sense that they try to trigger intent with some entity. By printing buttons variable I didn't saw that anything is wrong with the JSON format.
Error (including full traceback):
2019-07-18 13:15:53 ERROR rasa.core.channels.telegram - Exception when trying to handle message.Button_data_invalid
[2019-07-18 13:15:53 +0000] [1] [ERROR] Exception occurred while handling uri: 'http://a063c738.ngrok.io/webhooks/telegram/webhook'
Traceback (most recent call last):
cal/lib/python3.6/site-packages/sanic/app.py", line 917, in handle_request
response = await response
File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/telegram.py", line 228, in message
text, out_channel, sender_id, input_channel=self.name()
File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/channel.py", line 75, in handler
await app.agent.handle_message(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rasa/core/agent.py", line 440, in handle_message
return await processor.handle_message(message)
File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 84, in handle_message
await self._predict_and_execute_next_action(message, tracker)
File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 350, in _predict_and_execute_next_action
action, tracker, message.output_channel, self.nlg, policy, confidence
File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 461, in _run_action
await self._send_bot_messages(events, tracker, output_channel)
File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 382, in _send_bot_messages
await output_channel.send_response(tracker.sender_id, e.message())
File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/channel.py", line 179, in send_response
recipient_id, message.pop("text"), message.pop("buttons"), **message
File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/telegram.py", line 92, in send_text_with_buttons
self.send_message(recipient_id, text, reply_markup=reply_markup)
File "/usr/local/lib/python3.6/site-packages/telegram/bot.py", line 65, in decorator
result = func(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/telegram/bot.py", line 90, in decorator
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
File "/usr/local/lib/python3.6/site-packages/telegram/utils/request.py", line 309, in post
headers={'Content-Type': 'application/json'})
File "/usr/local/lib/python3.6/site-packages/telegram/utils/request.py", line 223, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Button_data_invalid
Thanks for raising this issue, @erohmensing will get back to you about it soon.
In most cases Rasa works perfectly well and the buttons are correctly displayed. But in some cases the following error occurs on the Rasa server (check the error's traceback below). Those cases are the similar as the one that works.
Can you pin down anything that is different about what works and what doesn't?
The last week that I posted this issue, I had two written cases (sentences that I send to bot) of one that works and one that doesn't. This week I have changed nlu data (only nlu.md file) and the nlu model is changed and with that the probabilities for intents. Now the cases that worked last week, doesn't work and the case that didn't work last week, now works. What do you think would be the most helpful to provide you here?
Now the cases that worked last week, doesn't work and the case that didn't work last week, now works.
Oh jeez haha 馃槄 that's super strange. In any case an example of what works and what doesn't at the moment should hopefully help.
Yeah, it's a miracle 馃槃
First case that doesn't work is when I send the following message:
Bot I want to know something about some person
The message is interpreted and the following is stored at the tracker store:
{
"event": "user",
"timestamp": 1563798338.76677,
"text": "Bot I want to know something about some person",
"parse_data": {
"intent": {
"name": "ask_information_about_expertise",
"confidence": 0.649138212203979
},
"entities": [],
"intent_ranking": [{
"name": "ask_information_about_expertise",
"confidence": 0.649138212203979
},
{
"name": "thanks",
"confidence": 0.396756500005722
},
{
"name": "company_information",
"confidence": 0.328071594238281
},
{
"name": "joke",
"confidence": 0.322005808353424
},
{
"name": "ask_information_about",
"confidence": 0.301791042089462
},
{
"name": "transfer_money",
"confidence": 0.273617535829544
},
{
"name": "ask_information_about_product",
"confidence": 0.272290468215942
},
{
"name": "ask_about_business_director",
"confidence": 0.216294944286346
},
{
"name": "get_banks",
"confidence": 0.192994967103004
},
{
"name": "ask_information_about_industries",
"confidence": 0.180114775896072
}
],
"text": "Bot I want to know something about some person"
},
"input_channel": "telegram"
}
The second case that does work is:
Tell me about product
And the following information is recorded at the tracker store:
{
"event": "user",
"timestamp": 1563798740.49272,
"text": "Tell me about product",
"parse_data": {
"intent": {
"name": "ask_information_about",
"confidence": 0.465203255414963
},
"entities": [],
"intent_ranking": [{
"name": "ask_information_about",
"confidence": 0.465203255414963
},
{
"name": "affirm",
"confidence": 0.413352251052856
},
{
"name": "thanks",
"confidence": 0.36239019036293
},
{
"name": "joke",
"confidence": 0.336913108825684
},
{
"name": "fintech_information",
"confidence": 0.305788218975067
},
{
"name": "ask_about_weather",
"confidence": 0.293225228786469
},
{
"name": "ask_about_vice_president_sales",
"confidence": 0.284141659736633
},
{
"name": "ask_information_about_product",
"confidence": 0.272731453180313
},
{
"name": "ask_information_about_software_development",
"confidence": 0.198083102703094
},
{
"name": "ask_information_about_industries",
"confidence": 0.183519542217255
}
],
"text": "Tell me about product"
},
"input_channel": "telegram"
}
And these are the cases that I mentioned before that switched from working to not working, and vice versa. 馃槃
I changed a logic of a custom action action_default_ask_affirmation a little bit, and now the action implementation is the following:
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> List['Event']:
intent_ranking = tracker.latest_message.get('intent_ranking', [])
if len(intent_ranking) > 1:
diff_intent_confidence = (intent_ranking[0].get("confidence") -
intent_ranking[1].get("confidence"))
if diff_intent_confidence < 0.2:
intent_ranking = intent_ranking[:2]
else:
intent_ranking = intent_ranking[:1]
first_intent_names = [intent.get('name', '')
for intent in intent_ranking
if intent.get('name', '') != 'out_of_scope']
message_title = ("Sorry, I'm not sure I've understood "
"you correctly 馃 Do you mean...")
entities = tracker.latest_message.get("entities", [])
entities = {e["entity"]: e["value"] for e in entities}
buttons = []
for intent in first_intent_names:
entity_from_mapping = list(self.intent_mappings[self.intent_mappings['intent'] == intent]['entities'].values[0])[0]
if entity_from_mapping in entities or entity_from_mapping == "":
"""Key already exists in dictonary. Appending regular button."""
entities_json = json.dumps(entities)
buttons.append({'title': self.get_button_title(intent, entities),
'payload': '/{}{}'.format(intent,
entities_json)})
else:
"""There was no entities in the last message"""
categorical_slots = domain['slots'][entity_from_mapping]['values']
for cat_slot in categorical_slots:
"""Iterate over values for categorical slot"""
slot_entity = {entity_from_mapping: cat_slot}
slot_entities_str = json.dumps(slot_entity)
buttons.append({'title': self.get_button_title(intent, slot_entity),
'payload': '/{}{}'.format(intent,
slot_entities_str)})
buttons.append({'title': 'Something else',
'payload': '/out_of_scope'})
dispatcher.utter_button_message(message_title, buttons=buttons, button_type="vertical")
return []
Changing the custom action for action_default_ask_affirmation didn't changed nothing regarding the stated problem. Printing the buttons variable for the first non-working case, just before the dispatcher utter button message call we get the following:
[{'title': 'managed software development expertise?', 'payload': '/ask_information_about_expertise{"expertise": "managed software development"}'}, {'title': 'quality assurance and testing expertise?', 'payload': '/ask_information_about_expertise{"expertise": "quality assurance and testing"}'}, {'title': 'embedded systems expertise?', 'payload': '/ask_information_about_expertise{"expertise": "embedded systems"}'}, {'title': 'iot and predictive analytics expertise?', 'payload': '/ask_information_about_expertise{"expertise": "iot and predictive analytics"}'}, {'title': 'digital security expertise?', 'payload': '/ask_information_about_expertise{"expertise": "digital security"}'}, {'title': 'mobility expertise?', 'payload': '/ask_information_about_expertise{"expertise": "mobility"}'}, {'title': 'cloud expertise?', 'payload': '/ask_information_about_expertise{"expertise": "cloud"}'}, {'title': 'chatbot expertise?', 'payload': '/ask_information_about_expertise{"expertise": "chatbot"}'}, {'title': 'agile expertise?', 'payload': '/ask_information_about_expertise{"expertise": "agile"}'}, {'title': 'Something else', 'payload': '/out_of_scope'}]
For the case that works:
```
[{'title': 'expertises information', 'payload': '/ask_information_about{"branch": "expertises"}'}, {'title': 'industries information', 'payload': '/ask_information_about{"branch": "industries"}'}, {'title': 'Yes', 'payload': '/affirm{}'}, {'title': 'Something else', 'payload': '/out_of_scope'}]
````
If you think that something else is also relevant, or you think that i missed something, just tell me and I will post it.
Ok. Hm. There are a lot of potential things that could go wrong here, although from a first look I can't see anything that screams that it would be an issue. Any chance you could play around with your code to try to create a minimal reproducible example? E.g. does this same thing happen in a regular action, can you pull out any extra buttons that don't affect the response 1 by 1, etc?
Sorry to ask, it's just that there's so much going on it's hard to tell where the error could be coming from.
You could also post the HTTP requests to your ngrok channels as they have a UI where you can look at the requests and their responses -- ideally one that returns the BadRequest error and one that returns a 200
I met a similar problem. I recognized that telegram limit payload size so we can not attach data with long text.
Aha @bambootran89 thanks for the information! Where did you find that and what's the limit? We should throw a warning in the telegram file if the user tries to attach a too-long payload then
@erohmensing we can check at this link "https://core.telegram.org/bots/api". InlineKeyboardButton

This issue has been automatically closed because there has been no response to our request for more information from the original author. Without this, we don't have enough information to help you. Please comment below with the requested information if you still need help.
Aha @bambootran89 thanks for the information! Where did you find that and what's the limit? We should throw a warning in the telegram file if the user tries to attach a too-long payload then
@bambootran89 has provided answer to your question @erohmensing
I apologize, I did take a look at that, but couldn't find anywhere information about the maximum length. Could you find that @bambootran89 ?
@erohmensing I think that @bambootran89 pointed to callback_data and to the information that it shouldn't be larger than 64 bytes.
We can see that on the following link (master branch of the Rasa, not the version that I have used for testing) we're providing callback_data with the payload that we have specified for each button.
https://github.com/RasaHQ/rasa/blob/13461d6d55ed70f4d941a533858cfe9baf5889f9/rasa/core/channels/telegram.py#L62
There is the possibility that when payload was constructed some of the entity names were too long.
Ah, can't believe I missed that. Thanks for the explanation. How do you think this should be handled? In my opinion, I would have it return the first 64 chars, and then log a warning so that the user can see why the bot most likely behaved incorrectly (e.g. if all of the entities did not make it in)
(master branch of the Rasa, not the version that I have used for testing)
are you already testing to make sure this is the case? If so, we'd love to approve a PR from you fixing this.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed due to inactivity. Please create a new issue if you need more help.