- Telegram doesn't have traditional REST API where we generate a client and use that to interact with the API. We instead have bots that can act as an actual telegram account and can be controlled via code.
- We use a single bot for both attestation and rewarding user.
- The Bot is, at present, a passive one: It doesn't try to start a conversation with anyone or sends messages to anyone or any group. However, it replies to every message sent to it via DM.
- For most part, the bot only reads the messages sent in private and in groups it is added to.
- All the updates that we receive through webhooks or polling is from the bots.
Bridge can receive telegram updates in two ways:
- Using webhooks: Bridge exposes an endpoint that is registered with Telegram as a webhook. When an event happens, telegram posts the update to the webhook
- Without webhook: Bridge polls the Telegram API every few seconds for new updates
An update isn't always a message. It can also be events like a user joining a group or leaving a group.
To listen to a group's events and messages, you have to add the bot to the group.
Bridge, by behaviour, only looks for messages directly sent to the bot and new_chat_members event on groups originprotocolkorea and originprotocol
- When a direct message is received,
- If it is a
/startcommand with valid address param, it creates a telegram attestation entry. - Otherwise, the chat message is logged to the DB and emailed to support@originprotocol.com
- If it is a
- When
new_chat_membersevent exists, it creates theFollowedOnTelegramgrowth event
- When running in webhook mode, the reply message has to be written to the response stream before ending it.
- When polling, a separate XHR request has to be made. This has rate-limit of 30 messages per second (overall and across all users)
- Remove the key
TELEGRAM_DISABLE_WEBHOOKSor set it's tofalse - Restart the bridge server
- Go to following URL in the browser:
/hooks/telegram/__init
- Set
TELEGRAM_DISABLE_WEBHOOKStotrue - Restart the bridge server
Send a POST request (using postman or any HTTP client/library) to /hooks/telegram/__getWebhookInfo
The value of authorization header should be same as env variable WEBHOOK_ADMIN_SECRET
Send a POST request to /hooks/telegram/__deleteWebhook with authorization header. This deletes the webhook but doesn't start polling
Send a POST request to /hooks/telegram/__clearQueue with authorization header. This recursively marks the first 10k messages on the queue as read
- It is not possible to get updates through polling/HTTP requests, when a webhook is active. So, you have to delete the webhook. If you start polling on bridge, it tries and deletes webhook before starting
- To check the logs, you have to check the logs of the bridge.