Thread: [Plugin] Telegram Connector
View Single Post
Old 26/01/2019, 02:18 AM   #7
SyS's Avatar
Join Date: Oct 2015
Posts: 1,950
Reputation: 500
Default Re: Telegram Connector

Originally Posted by Chaprnks View Post
Thank you so much for this plugin!

I can't for the life of me, seem to figure out how to find the chat id of my channel.. even tried using the GetIDsBot telegram bot with no luck.. lol
There are couple of tricks to get chat id of a private channel.Here's one you can do in pawn itself.

Add your bot as admin in your channel.
Make channel public and set a user name (username is one along with invite link).
Use TGSendMessage with chatid as user username with a prefix '@' and specify a callback.
Use TGCacheGetChatId to get chatid stored inside the cache.

For example my channel' username is samptest
Use following snippet

PHP Code:
new TGBot:g_bot;

main() {
g_bot TGConnectFromEnv("SAMP_TG_BOT");
TGSendMessage(g_bot,TGChatId:"@samptest","test message",.callback="OnChannelSendMessage");

forward OnChannelSendMessage(TGBot:bot,TGMessage:messageid);
OnChannelSendMessage(TGBot:bot,TGMessage:messageid) {
printf("the chatid is %s",_:chatid);

Now you can set the channel back to private.
You can also do the same by sending an api request in your browser with chatid parameter as your channel username or use OnTGChannelPost callback and send a message to your channel manually and use TGCacheGetChatId there.
SyS is offline   Reply With Quote