Skip to content
Telegram connector for samp
Rust Pawn SourcePawn Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
include update to latest sdk May 14, 2019
pawn-examples fix non inuitive directory structure Feb 9, 2019
pawn-tests update to latest sdk May 14, 2019
src update to latest sdk May 14, 2019
.gitignore sublime text configuration May 24, 2019
.travis.yml enable cargo caching and update sampctl Apr 18, 2019
Cargo.lock update to latest sdk May 14, 2019
Cargo.toml update to latest sdk May 14, 2019
LICENSE Initial commit Jan 15, 2019
README.md info about wiki Jan 25, 2019
TgConnector.sublime-project sublime text configuration May 24, 2019
appveyor.yml
bintray.json ci config fixed May 14, 2019
makefile update to latest sdk May 14, 2019
pawn.json update to latest sdk May 14, 2019

README.md

TgConnector

Build Status Build status sampctl-supported GitHub issues GitHub pull requests GitHub pull license

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

Installing

If you are a sampctl user

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

    git clone https://github.com/Sreyas-Sreelal/tgconnector.git

  • Use makefile to compile and test

    • Setup testing environment

      make setup

    • To build release version

      make release

    • Run tests

      make run

API

Checkout the Wiki

Example

A basic bot

#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[12],
		username[24],
		chatname[56],
		server_msg[128];

	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[12],
		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;
}
You can’t perform that action at this time.