# Telegram integration with rasa

**URL:** <https://forum.rasa.com/t/telegram-integration-with-rasa/41940>\
**Category:** Rasa Open Source\
**Created:** [March 31, 2021, 5:36pm UTC](https://forum.rasa.com/t/telegram-integration-with-rasa/41940 "2021-03-31T17:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiolamfleury](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fabiolamfleury/32/13249_2.png) [@fabiolamfleury](https://forum.rasa.com/u/fabiolamfleury)\
**Post date:** [March 31, 2021, 5:36pm UTC](https://forum.rasa.com/t/telegram-integration-with-rasa/41940/1 "2021-03-31T17:36:59Z")

</div>

I made my bot connect to telegram and right now it is working. But i have different flows, if the bot is in a group or in a individual chat. I tried to retrieve some information and read the telegram API but only got more confused on how to do it. During a flow, i have an action to see where the bot is at.

```
  - story: Greet user
    steps:
      - intent: start
      - action: action_check_channel

```

If the bot is in telegram, i would like to now if it is in a group chat or not, so i did this request:

[https://api.telegram.org/bot${TELEGRAM\_TOKEN}/getChat](https://api.telegram.org/bot%24%7BTELEGRAM_TOKEN%7D/getChat)

The Response i got:

`{"ok":false,"error_code":400,"description":"Bad Request: chat_id is empty"}`

---

<div class="post-metadata">

**Author:** ![fabiolamfleury](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fabiolamfleury/32/13249_2.png) [@fabiolamfleury](https://forum.rasa.com/u/fabiolamfleury)\
**Post date:** [April 1, 2021, 2:21am UTC](https://forum.rasa.com/t/telegram-integration-with-rasa/41940/2 "2021-04-01T02:21:32Z")

</div>

Going to post the solution i found:

Implemented a custom input channel in a file called `custom_telegram.py` the same folder that the `credentials.yml` is, with the content:

```
from rasa.core.channels import TelegramInput
from typing import Text

class TelegramInputChannel(TelegramInput):
    def get_metadata(self, request):
        metadata=request.json
        return metadata

```

Then, edited my `credentials.yml` using:

```
custom_telegram.TelegramInputChannel:
  access_token: "token provided by father bot"
  verify: "bot_username"
  webhook_url: "https://address/webhooks/telegram/webhook"

```

After that, it was possible to access in actions file:

```
    telegram_username = tracker.latest_message["metadata"]["from"]["username"] #user that sent the message
    telegram_chat_type = tracker.latest_message["metadata"]["chat"]["type"]
    if telegram_chat_type == 'group':
        is_group = True
    return [
                SlotSet("is_in_telegram_group", is_group),
            ]
```

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [September 14, 2021, 1:29pm UTC](https://forum.rasa.com/t/telegram-integration-with-rasa/41940/3 "2021-09-14T13:29:13Z")

</div>

hello @fabiolamfleury , Can you help with an issue that i have, i am trying to connect rasa with telegram (am not using ngrok because i have an accessible ip ) but i have error 423 : too many requests retry after I am using docker rasa-x how can i do ? is it a port problem ? thanks @fabiolamfleury
