Telegram Connector -
SyS - 21.01.2019
Installing
If you are a sampctl user
Code:
sampctl p install Sreyas-Sreelal/tgconnector
OR
- Download suitable binary files from releases for your operating system
- Add it your plugins folder
- Add tgconnector to server.cfg or tgconnector.so (for linux)
- Add tgconnector.inc in includes folder
Building
- Clone the repo
- Use makefile to compile and test
- Setup testing environment
- To build release version
- Run tests
Example
A basic bot
pawn Code:
#include<a_samp>
#include<tgconnector>
#include<zcmd>
#define CHAT_ID (TGChatId:"YOUR_CHAT_ID_HERE")
new TGBot:g_bot;
main() {
//Store bot token in SAMP_TG_BOT environment variable and connect from it
g_bot = TGConnectFromEnv("SAMP_TG_BOT");
if(g_bot != INVALID_BOT_ID) {
printf("bot connected successfully!");
} else {
printf("Error: bot couldn't connect");
}
}
public OnTGMessage(TGBot:bot,TGUser:fromid,TGMessage:messageid) {
if(g_bot != bot){
return 1;
}
new
message[50],
username[24],
chatname[56],
server_msg[128];
TGCacheGetMessage(message);
TGCacheGetUserName(username);
TGCacheGetChatName(chatname);
format(server_msg,128,"[%s] %s(%d): %s",chatname,username,_:fromid,message);
SendClientMessageToAll(-1,server_msg);
return 1;
}
public OnTGUserJoined(TGBot:bot,TGUser:userid) {
new
TGChatId:chatid[15],
username[24],
chatname[56],
server_msg[128];
//Retrive data stored in current context
TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
format(server_msg,128,"User %s(%d) joined %s(%s)",username,_:userid,chatname,_:chatid);
SendClientMessageToAll(-1,server_msg);
return 1;
}
public OnTGUserLeft(TGBot:bot,TGUser:userid) {
new
TGChatId:chatid[15],
username[24],
chatname[56],
server_msg[128];
TGCacheGetUserName(username);
TGCacheGetChatId(chatid);
TGCacheGetChatName(chatname);
format(server_msg,128,"User %s(%d) left %s(%s)",username,_:userid,chatname,_:chatid);
SendClientMessageToAll(-1,server_msg);
return 1;
}
CMD:sendtgmessage(playerid,params[]) {
TGSendMessage(g_bot,CHAT_ID,params);
return 1;
}
Notes
This plugin is still in WIP and more tests need to be done.If you find any bugs or have anything to contribute feel free to open an issue or pull request on github.
Also be sure to not to share your bot token with anyone it's recommended to store it inside a environment variable.
Repository
Source:
https://github.com/Sreyas-Sreelal/tgconnector
Releases:
https://github.com/Sreyas-Sreelal/tgconnector/releases
Wiki:
https://github.com/Sreyas-Sreelal/tgconnector/wiki (Not complete yet)
Re: Telegram Connector -
Hazon - 21.01.2019
Going to test, wd.
Re: Telegram Connector -
SyS - 22.01.2019
New version (v0.1.0)
https://github.com/Sreyas-Sreelal/tg...ases/tag/0.1.0- Channel updates are now serialized correctly.
- New callback OnTGChannelPost has been added.
Re: Telegram Connector -
NimA00GaMeR - 22.01.2019
Wowwww.
It's Great!
Re: Telegram Connector -
Kar - 22.01.2019
Lol telegram, good job!
Re: Telegram Connector -
Chaprnks - 25.01.2019
Thank you so much for this plugin!
Update:
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
Re: Telegram Connector -
SyS - 26.01.2019
Quote:
Originally Posted by Chaprnks
Thank you so much for this plugin!
Update:
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);
public OnChannelSendMessage(TGBot:bot,TGMessage:messageid) {
new TGChatId:chatid[15];
TGCacheGetChatId(chatid);
printf("the chatid is %s",_:chatid);
return 1;
}
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.
Re: Telegram Connector -
Chaprnks - 26.01.2019
Quote:
Originally Posted by SyS
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);
public OnChannelSendMessage(TGBot:bot,TGMessage:messageid) {
new TGChatId:chatid[15];
TGCacheGetChatId(chatid);
printf("the chatid is %s",_:chatid);
return 1;
}
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.
|
Thank you so much! It's odd how they make it so difficult to find something as simple as a ID field..
Re: Telegram Connector -
SyS - 26.01.2019
Quote:
Originally Posted by Chaprnks
Thank you so much! It's odd how they make it so difficult to find something as simple as a ID field..
|
It's true.But still forwarding message to @get_id_bot is easier way and idk why it didn't work for you.
Re: Telegram Connector -
GhostHacker9 - 07.02.2019
Wtf why I didn't see this before.This is so great!Thank you so much
Re: Telegram Connector -
SyS - 14.05.2019
New version (v0.1.1)
https://github.com/Sreyas-Sreelal/tg...ases/tag/0.1.1- updated to latest sdk
- added optional parameter thread_limit for natives TGConnect and TGConnectFromEnv
Re: Telegram Connector -
Marshall32 - 19.07.2019
Thanks!
Re: Telegram Connector -
FinStar - 20.07.2019
Anybody know what to do with it?
[18:22:26] Loading plugin: tgconnector.so
[18:22:26] Failed (libssl.so.1.0.0: cannot open shared object file: No such file or directory)
Actually, I have openssl installed. debian 8 (86_64x)
Re: Telegram Connector -
SyS - 21.07.2019
Quote:
Originally Posted by FinStar
Anybody know what to do with it?
[18:22:26] Loading plugin: tgconnector.so
[18:22:26] Failed (libssl.so.1.0.0: cannot open shared object file: No such file or directory)
Actually, I have openssl installed. debian 8 (86_64x)
|
You may have different version of openssl or different architecture. (you need 32 bit libs not 64)
Try using arch linux build. It's compiled against openssl.11.If that didn't work try building the plugin in your machine. If that's not possible I will try to make a release for Debian 8
Re: Telegram Connector -
SiaReyes - 21.07.2019
D*mn this is awsome Good Job!
Re: Telegram Connector -
FinStar - 21.07.2019
Quote:
Originally Posted by SyS
You may have different version of openssl or different architecture. (you need 32 bit libs not 64)
Try using arch linux build. It's compiled against openssl.11.If that didn't work try building the plugin in your machine. If that's not possible I will try to make a release for Debian 8
|
You could release the debian version, please?
Re: Telegram Connector -
Marshall32 - 30.07.2019
Quote:
Originally Posted by FinStar
You could release the debian version, please?
|
Did you try what sys told you? Install openssl on your server.
Code:
apt-get install libssl-dev:i386
Re: Telegram Connector -
N0FeaR - 31.07.2019
Awesome i will use this!
Re: Telegram Connector -
SyS - 07.01.2020
New version released
https://github.com/Sreyas-Sreelal/tg...ases/tag/0.2.0
Re: Telegram Connector -
lexjusto - 11.01.2020
Hi, great plugin. Can I have an example of a code for sending a message with Cyrillic alphabet?