Giter VIP home page Giter VIP logo

tgconnector's Introduction

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 = TG_ConnectFromEnv("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];

	TG_CacheGetMessage(message);
	TG_CacheGetUserName(username);
	TG_CacheGetChatName(chatname);

	format(server_msg,128,"[%s] %s(%s): %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];

	TG_CacheGetUserName(username);
	TG_CacheGetChatId(chatid);
	TG_CacheGetChatName(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];

	TG_CacheGetUserName(username);
	TG_CacheGetChatID(chatid);
	TG_CacheGetChatName(chatname);

	format(server_msg,128,"User %s(%s) left %s(%s)",username,_:userid,chatname,_:chatid);
	SendClientMessageToAll(-1,server_msg);
	return 1;
}

CMD:sendtgmessage(playerid,params[]) {
	TG_SendMessage(g_bot,CHAT_ID,params);
	return 1;
}

tgconnector's People

Contributors

sreyas-sreelal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tgconnector's Issues

Support proxy.

Hi .If possible, you need to add settings for the proxy. (in some countries, telegram is blocked (for example: Russia)

[TgConnector] [error]

[18:02:06] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:02:36] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:02:49] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:02:52] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:03:09] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:03:12] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:03:49] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"
[18:04:00] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })) }, X509VerifyResult { code: 0, error: "ok" })))"

Offer. Add Cyrillic support.

I propose to add support for Russian letters. Previously contacted the author, and did not understand whether there will be an update in the near future.
Now I am actively developing based on this api, and this will help me and other users of the Russian-speaking community a lot!
Thank you in advance.

OpenSSL Debian 11

[00:59:57] Loading plugin: tgconnector.so
[00:59:57] Failed (libssl.so.1.1: cannot open shared object file: No such file or directory)

Crash server

Hey. I had a server crash with online. I suspect your plugin, because Crashdetect did not want to show the exact reason. (crashdetect 4.19 version, try update, to 4.19.4, mb show reason)

Showed only this:
[31/01/2019 15:20:28] [debug] Server crashed due to an unknown error

The last thing I did, I sent a message to the telegraph group.
Messages catch through:
public OnTGMessage(TGBot:bot, TGUser:fromid, TGMessage:messageid)

Help fix it, tk. Before this, the server with online 100 worked stably.
Ready to help if you need it.

OnTGMessage(TGBot:bot,TGUser:fromid[],TGMessage:messageid) doesn't work

Hello!
I'm trying to call OnTGMessage. But it doesn't work. My code doesn't output "yes".
`public OnTGMessage(TGBot:bot,TGUser:fromid[],TGMessage:messageid) {

print("yes");
if(g_bot != bot){
	return 1;
}

new
	message[50],
	username[24],
	chatname[56],
	server_msg[128];

TG_CacheGetMessage(message);
TG_CacheGetUserName(username);
TG_CacheGetChatName(chatname);

format(server_msg,128,"[%s] %s(%s): %s",chatname,username,_:fromid,message);
print(server_msg);
SendClientMessageToAll(-1,server_msg);

return 1;

}`

This is not accompanied by any errors.

Connection error

Hi.

[2024-04-03T10:08:00+0300] [Info] [TgConnector] [error]: "Error sending request to telegram api\nSSLHandshake(Failure(Ssl(Error { code: ErrorCode(5), cause: Some(Io(Os { code: 104, kind: ConnectionReset, message: \"Connection reset by peer\" })) }, X509VerifyResult { code: 0, error: \"ok\" })))"

PLUGIN LOAD FAILED

Loading plugin: tgconnector.so
[18:06:25] Failed (libssl.so.1.1: cannot open shared object file: No such file or directory)
why?
host maze-host

Crashes after gmx command

Sometimes there are crashes when restarting a mod via gmx

Debian 11

[05:03:13] [debug] Server crashed while executing new.amx
[05:03:13] [debug] AMX backtrace:
[05:03:13] [debug] #0 native TG_Connect () in tgconnector.so
[05:03:13] [debug] #1 002f8ec4 in public OnGameModeInit_Inv () at new.pwn:8844
[05:03:13] [debug] #2 002d0f20 in public OnGameModeInit_Pool () at ../sourse/inventory/public/On_GameMode.pwn:15
[05:03:13] [debug] #3 00130f7c in public OnGameModeInit_quest () at ../sourse/pool.pwn:1739
[05:03:13] [debug] #4 000f70fc in public OnGameModeInit_quest_work () at ../sourse/quest/0_main.pwn:214
[05:03:13] [debug] #5 000ef440 in public OnGameModeInit_debug () at ../sourse/quest/stage_1/mission_6/quest_work_beach.pwn:263
[05:03:13] [debug] #6 00089690 in public PHY_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\weapon-config.inc:2809
[05:03:13] [debug] #7 native CallLocalFunction () in samp03svr
[05:03:13] [debug] #8 00075ba8 in public ac_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\physics.inc:195
[05:03:13] [debug] #9 00018038 in public MDialog_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\nex-ac.inc:3629
[05:03:13] [debug] #10 000071fc in public Iter_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\mdialog.inc:387
[05:03:13] [debug] #11 00005750 in public PawnRakNet_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\foreach.inc:662
[05:03:13] [debug] #12 0000569c in public PawnCmd_OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\Pawn.RakNet.inc:1153
[05:03:13] [debug] #13 00001c5c in public SSCANF_OnGameModeInit ()  at C:\Users\Bren8\Desktop\Server-RP\pawno\include\Pawn.CMD.inc:131
[05:03:13] [debug] #14 000013a4 in public OnGameModeInit () at C:\Users\Bren8\Desktop\Server-RP\pawno\include\sscanf2.inc:1066
[05:03:13] [debug] Native backtrace:
[05:03:13] [debug] #0 f7a4762f in _Z13GetStackTraceRSt6vectorI10StackFrameSaIS0_EEPv () in plugins/crashdetect.so
[05:03:13] [debug] #1 f7a3f53d in _ZN11CrashDetect20PrintNativeBacktraceERSoRKN2os7ContextE () in plugins/crashdetect.so
[05:03:13] [debug] #2 f7a40d58 in _ZN11CrashDetect20PrintNativeBacktraceERKN2os7ContextE () in plugins/crashdetect.so
[05:03:13] [debug] #3 f7a40f1c in _ZN11CrashDetect7OnCrashERKN2os7ContextE () in plugins/crashdetect.so
[05:03:13] [debug] #4 f7a46edf in ?? () in plugins/crashdetect.so
[05:03:13] [debug] #5 f7fbe580 in __kernel_rt_sigreturn () in linux-gate.so.1
[05:03:13] [debug] #6 f7fbe559 in __kernel_vsyscall () in linux-gate.so.1
[05:03:13] [debug] #7 f7ae2e02 in gsignal () in /lib/i386-linux-gnu/libc.so.6
[05:03:13] [debug] #8 f7acb306 in abort () in /lib/i386-linux-gnu/libc.so.6
[05:03:13] [debug] #9 efcd52a5 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #10 efcd5285 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #11 efd04b15 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #12 efd06881 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #13 efd0651b in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #14 efd06475 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #15 efd0645a in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #16 efca3a97 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #17 efca3e27 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #18 efd313b3 in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #19 efd0a1ac in ?? () in plugins/tgconnector.so
[05:03:13] [debug] #20 080950e4 in ?? () in ./samp03svr
[05:03:13] [debug] #21 f7a42168 in _ZN11CrashDetect10OnCallbackEiPiS0_ () in plugins/crashdetect.so
[05:03:13] [debug] #22 f7a452ab in ?? () in plugins/crashdetect.so
[05:03:13] [debug] Registers:
[05:03:13] [debug] EAX: 00000000 EBX: 00000002 ECX: fffaa3dc EDX: 00000000
[05:03:13] [debug] ESI: 00000008 EDI: 00000000 EBP: fffaa3dc ESP: fffaa3c0
[05:03:13] [debug] EIP: f7fbe559 EFLAGS: 00200246
[05:03:13] [debug] Stack:
[05:03:13] [debug] ESP+00000000: fffaa3dc 00000000 fffaa3dc f7ae2e02
[05:03:13] [debug] ESP+00000020: 00000000 00000002 fffaa5c8 efce17d8
[05:03:13] [debug] ESP+00000040: 00000000 00000058 efd51b6c efd6b51c
[05:03:13] [debug] ESP+00000060: fffaa5c8 fffaa49a 00000002 efcb2c60
[05:03:13] [debug] ESP+00000080: f7fa7000 00000000 efd516b6 fffaa49a
[05:03:13] [debug] ESP+000000a0: fffffffe ffffffff ffffffff ffffffff
[05:03:13] [debug] ESP+000000c0: ffffffff ffffffff ffffffff ffffffff
[05:03:13] [debug] ESP+000000e0: ffffffff ffffffff ffffffff ffffffff
[05:03:13] [debug] ESP+00000100: ffffffff ffffffff ffffffff ffffffff
[05:03:13] [debug] ESP+00000120: 00000000 0d45b9a0 00000000 f7ab0c80
[05:03:13] [debug] ESP+00000140: 00000006 fffaa510 00000000 fffaa514
[05:03:13] [debug] ESP+00000160: 00000000 00000000 00000000 00000000
[05:03:13] [debug] ESP+00000180: 00000000 00000000 00000000 00000000
[05:03:13] [debug] ESP+000001a0: 00000000 00000000 00000000 00000000
[05:03:13] [debug] ESP+000001c0: 00000000 00000000 00000000 00000000
[05:03:13] [debug] ESP+000001e0: 00000000 00000020 f7c96003 fffaa680
[05:03:13] [debug] ESP+00000200: fffaa5d8 00000001 efd6cd04 f7c96000
[05:03:13] [debug] ESP+00000220: efd6b77c 00000001 efd51dfc 00000000
[05:03:13] [debug] ESP+00000240: fffaa640 fffaa680 fffaa618 efce0986
[05:03:13] [debug] ESP+00000260: efd6b77c 00000001 efd51dfc efd6cdd0
[05:03:13] [debug] ESP+00000280: 00000004 fffaa638 efd6cdd0 efcd5285
[05:03:13] [debug] ESP+000002a0: 0bbc0a20 efd6cdd0 efd6cdd0 efd06881
[05:03:13] [debug] ESP+000002c0: 0000000e 00000000 02000034 00000000
[05:03:13] [debug] ESP+000002e0: 00000007 f7c96740 efd4f7f5 00000009
[05:03:13] [debug] ESP+00000300: fffaa7b8 efd6ca4c f7accf01 086a7a70
[05:03:13] [debug] ESP+00000320: e53fbba8 00000001 efd6ca4c fffaa718
[05:03:13] [debug] ESP+00000340: fffaa7b8 efd6ca4c 00000001 efd06490
[05:03:13] [debug] ESP+00000360: 0000007b fffaa7b8 fffaa7d8 efd6b854
[05:03:13] [debug] ESP+00000380: e53fbb40 fffaa79b efd6cdd0 efd0645a
[05:03:13] [debug] ESP+000003a0: efd6ca4c f7c96000 efd6cdd0 efca3a97
[05:03:13] [debug] ESP+000003c0: 00001001 f7c96000 efd6cdd0 efca3e27
[05:03:13] [debug] ESP+000003e0: fffaa800 efd6ca1c fffaa798 efcb3660
[05:03:13] [debug] Loaded modules:
[05:03:13] [debug] 00000000 - 00187dc3 samp03svr
[05:03:13] [debug] f7fbe000 - f7fbf350 linux-gate.so.1
[05:03:13] [debug] f7faa000 - f7face40 /lib/i386-linux-gnu/libdl.so.2
[05:03:13] [debug] f7f88000 - f7fa79db /lib/i386-linux-gnu/libpthread.so.0
[05:03:13] [debug] f7dbd000 - f7f94518 /usr/lib/i386-linux-gnu/libstdc++.so.6
[05:03:13] [debug] f7cb9000 - f7dbbab0 /lib/i386-linux-gnu/libm.so.6
[05:03:13] [debug] f7c9a000 - f7cb6440 /lib/i386-linux-gnu/libgcc_s.so.1
[05:03:13] [debug] f7ab2000 - f7c9ffd2 /lib/i386-linux-gnu/libc.so.6
[05:03:13] [debug] f7fc0000 - f7fea3fb /lib/ld-linux.so.2
[05:03:13] [debug] f7a25000 - f7aafa04 plugins/crashdetect.so
[05:03:13] [debug] f7fb2000 - f7fb4858 plugins/bscrashfix.so
[05:03:13] [debug] f795f000 - f7a24740 plugins/streamer.so
[05:03:13] [debug] f794b000 - f7952d78 /lib/i386-linux-gnu/librt.so.1
[05:03:13] [debug] f78ea000 - f794a94a plugins/mysql.so
[05:03:13] [debug] f78c6000 - f78e9d32 /home/container/plugins/../log-core.so
[05:03:13] [debug] f74d4000 - f78c61c7 /home/container/plugins/libmysqlclient.so.18
[05:03:13] [debug] f6cbe000 - f6ccfad0 /lib/i386-linux-gnu/libnss_files.so.2
[05:03:13] [debug] f795a000 - f795cdfc plugins/FixRaknet.so
[05:03:13] [debug] f6ae7000 - f6cc888c plugins/pawnraknet.so
[05:03:13] [debug] f693d000 - f6af1349 plugins/sampvoice.so
[05:03:13] [debug] efff7000 - f01b973c plugins/pawncmd.so
[05:03:13] [debug] efe48000 - f0000bb8 plugins/pawnregex.so
[05:03:13] [debug] efe11000 - efe48844 plugins/sscanf.so
[05:03:13] [debug] efe0b000 - efe0e7a0 plugins/TOTP.so
[05:03:13] [debug] efe08000 - efe09ee8 plugins/samp_prot.so
[05:03:13] [debug] efd8b000 - efe0949c plugins/samp-precise-timers.so
[05:03:13] [debug] efd6e000 - efd89daf plugins/rustext.so
[05:03:13] [debug] efc9e000 - efd70c9c plugins/tgconnector.so
[05:03:13] [debug] efbfe000 - efc9b214 /usr/lib/i386-linux-gnu/libssl.so.1.1
[05:03:13] [debug] ef935000 - efc215a4 /usr/lib/i386-linux-gnu/libcrypto.so.1.1
[05:03:13] [debug] e9c00000 - e9c04824 /lib/i386-linux-gnu/libnss_dns.so.2
[05:03:13] [debug] e8f20000 - e8f3757c /lib/i386-linux-gnu/libresolv.so.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.