[Plugin] Telegram Connector
#1

TgConnector



A telegram connector plugin that helps to interact with telgram bots through SA-MP.
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

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)
Reply


Messages In This Thread
Telegram Connector - by SyS - 21.01.2019, 09:34
Re: Telegram Connector - by Hazon - 21.01.2019, 10:21
Re: Telegram Connector - by SyS - 22.01.2019, 06:08
Re: Telegram Connector - by NimA00GaMeR - 22.01.2019, 12:21
Re: Telegram Connector - by Kar - 22.01.2019, 13:23
Re: Telegram Connector - by Chaprnks - 25.01.2019, 22:00
Re: Telegram Connector - by SyS - 26.01.2019, 02:18
Re: Telegram Connector - by Chaprnks - 26.01.2019, 06:30
Re: Telegram Connector - by SyS - 26.01.2019, 07:17
Re: Telegram Connector - by GhostHacker9 - 07.02.2019, 01:25
Re: Telegram Connector - by SyS - 14.05.2019, 05:14
Re: Telegram Connector - by Marshall32 - 19.07.2019, 07:05
Re: Telegram Connector - by FinStar - 20.07.2019, 16:38
Re: Telegram Connector - by SyS - 21.07.2019, 02:34
Re: Telegram Connector - by SiaReyes - 21.07.2019, 03:53
Re: Telegram Connector - by FinStar - 21.07.2019, 11:16
Re: Telegram Connector - by Marshall32 - 30.07.2019, 02:10
Re: Telegram Connector - by N0FeaR - 31.07.2019, 00:19
Re: Telegram Connector - by SyS - 07.01.2020, 14:10
Re: Telegram Connector - by lexjusto - 11.01.2020, 02:09
Re: Telegram Connector - by oukibt - 18.02.2020, 13:15
Re: Telegram Connector - by SyS - 24.02.2020, 14:15
Re: Telegram Connector - by StargazerDC - 27.03.2020, 14:25
Re: Telegram Connector - by SyS - 31.03.2020, 02:59
Re: Telegram Connector - by SyS - 01.05.2020, 03:55
Re: Telegram Connector - by SyS - 10.07.2020, 05:32
Re: Telegram Connector - by bybyby - 16.07.2020, 07:46

Forum Jump:


Users browsing this thread: 1 Guest(s)