Recent

Author Topic: Telegram bots API Wrapper  (Read 10698 times)

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #15 on: July 11, 2018, 05:14:57 pm »
Ok, thanks, Mario

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #16 on: July 11, 2018, 08:37:00 pm »
I hope I understood you correctly and that's what you needed

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #17 on: July 12, 2018, 08:59:11 am »
Yes, thank you, I will do some tests in the next days.

Thanks, Mario

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #18 on: December 08, 2018, 03:50:09 pm »
Added some tests.
Added a simple procedural type to send a message via the bot (without creating a class).
 
Code: Pascal  [Select]
  1. { Procedure style method to send message from Bot to chat/user }
  2. function TgBotSendMessage(const AToken: String; chat_id: Int64; const AMessage: String;
  3.   out AReply: String;
  4.   ParseMode: TParseMode = pmDefault; DisableWebPagePreview: Boolean=False;
  5.   AReplyMarkup: TReplyMarkup = nil; ReplyToMessageID: Integer = 0): Boolean;
Brook-telegram added functions for calculating statistics for the day (events and unique users)
« Last Edit: December 08, 2018, 03:51:57 pm by Renat.Su »

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #19 on: December 15, 2018, 09:16:09 am »
SSH emulator via telegram
Anyone interested to manage a remote computer (a web server, a regular computer with access to the Internet) via telegrams, made a working example of the program source code https://github.com/Al-Muhandis/ShellRemoteBot
Actively tested on Linux (Debian), but should work on Windows. Instead of webhooks, longpolling is used to get updates from server telegrams, respectively, the program can work not only on a web server, but also on any home computer.
It is convenient to manage a web server via telegram in the phone.
The program can run as a console program that runs manually and as a service/daemon

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #20 on: December 15, 2018, 09:17:21 am »
Visually it looks like this

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #21 on: March 18, 2019, 07:46:41 pm »
1. Refactoring LongPollingDesktop example & other examples restructuring
2. Added some procedures for API
3. Payments API methods and implementations
4. Other fixes and improvements

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #22 on: March 19, 2019, 08:01:48 am »
Great job.

Thanks, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #23 on: August 08, 2019, 02:29:22 pm »
Hi,
cause of the problem reported here: https://forum.lazarus.freepascal.org/index.php/topic,39206.msg318360.html#msg318360 this component had problems on my Ubuntu 19.04.

I have solved with some simple modify on "tgsendertypes":
added at uses
Code: Pascal  [Select]
  1. sslsockets, fpopenssl, ssockets

Modified "HTTPPostJSON":
Code: Pascal  [Select]
  1. function TTelegramSender.HTTPPostJSON(const Method: String): Boolean;
  2. var
  3.   HTTP: TFPHTTPClient;
  4. begin
  5.   HTTP:=TFPHTTPClient.Create(nil);
  6.   try
  7.     HTTP.RequestBody:=TStringStream.Create(FRequestBody);
  8.     try
  9.       HTTP.AddHeader('Content-Type','application/json');
  10.       HTTP.OnGetSocketHandler:=@HttpClientGetSocketHandler;    <<<<<< added this line
  11.       FResponse:=HTTP.Post(FAPIEndPoint+FToken+'/'+Method);
  12.     finally
  13.       HTTP.RequestBody.Free;
  14.     end;
  15.     Result:=True;
  16.     DebugMessage('Response: '+FResponse);
  17.   except
  18.     Result:=False;
  19.     ErrorMessage('It is not succesful request to API! Request body: '+FRequestBody);
  20.   end;
  21.   HTTP.Free;
  22. end;
  23.  


Added the procedure:
Code: Pascal  [Select]
  1. procedure TTelegramSender.HttpClientGetSocketHandler(Sender: TObject;
  2.   const UseSSL: Boolean; out AHandler: TSocketHandler);
  3. begin
  4.   {$IFDEF LINUX}
  5.     if UseSSL then begin
  6.       AHandler:=TSSLSocketHandler.Create;
  7.       TSSLSocketHandler(AHandler).SSLType:=stTLSv1_1;  // <--
  8.     end;
  9.   {$ENDIF}
  10. end;
  11.  

With these modifies, all works fine again.

Can you made these modifies on your beautiful component?

Thanks in advance, Mario

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #24 on: August 09, 2019, 10:39:14 am »
Thank You very much! I will. Or You can (if You exists on github) to make pull request to lib and could accept this

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #25 on: August 09, 2019, 12:21:19 pm »
Sorry, i haven't an account on github

Hi, Mario

Renat.Su

  • Full Member
  • ***
  • Posts: 149
    • Renat.Su
Re: Telegram bots API Wrapper
« Reply #26 on: August 09, 2019, 02:20:14 pm »
Done! Thanks for the commit

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #27 on: August 09, 2019, 05:42:42 pm »
Thanks !

jdp

  • Jr. Member
  • **
  • Posts: 90
Re: Telegram bots API Wrapper
« Reply #28 on: August 25, 2019, 10:26:28 pm »
Hi. The package does not compile on Raspberry Pi.

I get this error.

tgsendertypes.pas(1746,45) Error: Identifier not found "stTLSv1_1"

Regards

bonmario

  • Sr. Member
  • ****
  • Posts: 299
Re: Telegram bots API Wrapper
« Reply #29 on: August 27, 2019, 09:23:29 am »
tgsendertypes.pas(1746,45) Error: Identifier not found "stTLSv1_1"

Wich version of FPC?
On fpc 3.0.4, stTLSv1_1 is declared in "....... / fpc / 3.0.4 / source / packages / openssl / src / fpopenssl.pp"


Hi, Mario