Issues with Custom message to Telegram from Rasa Action

Hi Guys,

I hope you are doing well, I am using Rasa Action to send a message to Telegram and I am able to see it on telegram, but it appears 5 times in telegram client with exceptions in Rasa. I am using NGROK with https on Rasa Connectors.

Could someone please help?

Here are exception details-

2020-05-10 18:39:39 ERROR    rasa.core.channels.telegram  - Exception when trying to handle message.Wrong url host
[2020-05-10 18:39:39 -0700] [12553] [ERROR] Exception occurred while handling uri: 'http://XXXXXXXXX.ngrok.io/webhooks/telegram/webhook'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/sanic/app.py", line 976, in handle_request
    response = await response
  File "/usr/local/lib/python3.7/site-packages/rasa/core/channels/telegram.py", line 252, in message
    metadata=metadata,
  File "/usr/local/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 83, in handler
    await app.agent.handle_message(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/agent.py", line 486, in handle_message
    return await processor.handle_message(message)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 107, in handle_message
    await self._predict_and_execute_next_action(message.output_channel, tracker)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 538, in _predict_and_execute_next_action
    action, tracker, output_channel, self.nlg, policy, confidence
  File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 651, in _run_action
    await self._send_bot_messages(events, tracker, output_channel)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 580, in _send_bot_messages
    await output_channel.send_response(tracker.sender_id, e.message())
  File "/usr/local/lib/python3.7/site-packages/rasa/core/channels/channel.py", line 193, in send_response
    await self.send_image_url(recipient_id, message.pop("image"), **message)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/channels/telegram.py", line 41, in send_image_url
    self.send_photo(recipient_id, image)
  File "/usr/local/lib/python3.7/site-packages/telegram/bot.py", line 65, in decorator
    result = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/telegram/bot.py", line 90, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))
  File "/usr/local/lib/python3.7/site-packages/telegram/utils/request.py", line 309, in post
    headers={'Content-Type': 'application/json'})
  File "/usr/local/lib/python3.7/site-packages/telegram/utils/request.py", line 223, in _request_wrapper
    raise BadRequest(message)
telegram.error.BadRequest: Wrong url host

It sounds like something might be wrong with the image URL; what does the custom action look like?

@mloubser Thanks for helping, it is still unresolved. Please find below code , I look forward to your reply.

class ActionGetName(Action):

    def name(self) -> Text:
        return "action_get_name"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        if tracker.get_slot("name") is None:
            dispatcher.utter_message(template='utter_ask_pin_code_again')
            return [UserUtteranceReverted()]
        else:
            name = tracker.get_slot("name")

            messages_list = [' Hello '  + name,
                             'How are you']
            message = "".join(messages_list)
            dispatcher.utter_message(message, tracker)
            return []

two things:

  1. you’re not actually using tracker for anything; you can just pass message
  2. If you did need to fill variables in a template from tracker slot values, you’d need to pass **tracker.slots, not just `tracker