Checking channel/group subscriptions on Telegram
Checking channel/group subscriptions works only on Telegram.
To check if a user is subscribed to a group/channel, you can query the Telegram API using the getChatMember method.
To do this make screens in the constructor:
1. Make a screen that has Request component where request method is set to POST.
2. Fill request URL:
https://api.telegram.org/bot<TOKEN>/getChatMember
Where <token> is your Telegram bot token. </token>
3. Add request body:
{ "chat_id": "<Channel_ID>", "user_id": "{{this_user.platform_id}}" }
Where:
- <channel_id></channel_id> is channel/group ID subscription of which you wish to check.
- user_id is ID of the user who we check for subscription. If left unchanged, the check will be done for a user who hit Request component in the bot.
4. Add the bot from which the request will be sent by an fully authorised administrator to the group/channel which subscription will be checked.
5. Add a screen with a Fork. Set up transition from Request to Fork if the request is successful.
6. last_request.result.status will be checked, that is the Fork will get value of this variable.
7. Set Fork Target to take user to other screens depending on whether they are subscribed.
Server response to a query can set last_request.result.status to any of the following:
- member – user is a subscribed,
- left – user is unsubscribed,
- kicked – user was kicked,
- administrator – user is an administrator,
- creator – user is a channel/group creator.
Set up Fork Target for each response, so that user is taken to the relevant screen depending on the server response.
8. Make screens with reports to the user.