Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Releases Plugins [Plugin] Telegram Connector

 
  • 2 Vote(s) - 5 Average
Plugin Telegram Connector
SyS
Offline

Burgershot Member
Posts: 37
Threads: 5
Joined: Apr 2019
Reputation: 4
#1
2019-04-14, 06:38 AM (This post was last modified: 2019-04-15, 03:48 AM by Kar.)
TgConnector

[Image: tgconnector.svg?branch=master] [Image: snip8i9cd6xh2x1u?svg=true] [Image: sampctl-TGConnector-2f2f2f.svg] [Image: tgconnector.svg] [Image: tgconnector.svg] [Image: tgconnector.svg]

A telegram connector plugin that helps to interact with telgram bots through SA-MP.

Installing

If you are a sampctl user

PHP 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

    PHP Code:
    git clone https://github.com/sreyas-sreelal/tgconnector.git 


  • Use makefile to compile and test
    • Setup testing environment

      PHP Code:
      make setup 


    • To build release version

      PHP Code:
      make release 


    • Run tests

      PHP Code:
      make run 


Example

A basic bot

PHP 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)
« Next Oldest | Next Newest »



Messages In This Thread
Telegram Connector - by SyS - 2019-04-14, 06:38 AM
RE: Telegram Connector - by Salesman - 2019-04-16, 12:43 PM
RE: Telegram Connector - by SyS - 2019-05-14, 05:09 AM
RE: Telegram Connector - by Gravityfalls - 2019-05-14, 08:17 AM
RE: Telegram Connector - by Sasino97 - 2019-06-11, 06:51 AM
RE: Telegram Connector - by SyS - 2020-05-01, 03:52 AM
RE: Telegram Connector - by SyS - 2020-07-10, 05:36 AM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode