Get Telegram updates via Long Polling, Webhooks, or Websockets
masterTelegram is an event-driven platform. You can retrieve updates (like new messages) using three primary methods:
- Long Polling: Send a request to the
getUpdatesendpoint. Uselimitandoffsetto manage the queue andtimeoutto hold the connection. - Webhooks: Redirect all updates to your own endpoint by calling
setWebhook. The URL must be URL-encoded in the query string. - Websockets: Connect to the
/eventsendpoint to receive all events as JSON-RPC 2.0 formatted objects. This is an efficient alternative to webhooks.
When using multiple sessions, you can subscribe to a specific session's events by appending the session name to the websocket path (e.g., ws://127.0.0.1:9503/events/session_name).
# Long Polling example
curl "127.0.0.1:9503/api/getUpdates?limit=3&offset=0&timeout=10.0" -g
# Webhook setup example
curl "127.0.0.1:9503/api/setWebhook?url=http%3A%2F%2Fexample.com%2Fsome_webhook" -g