Italian community of Lazarus and Free Pascal

Programmazione => Componenti Aggiuntivi => Topic aperto da: clayrm - Dicembre 01, 2017, 04:22:53 pm

Titolo: Telegram Bot
Inserito da: clayrm - Dicembre 01, 2017, 04:22:53 pm
Ciao a tutti.
Per python esiste un'ottima libreria da usare per gestire un bot Telegram, si chiama Telepot.
Sapete se esiste qualcosa del genere anche per Lazarus?
Ho fatto molte ricerche con google ma ne ho trovata soltanto una, tra l'altro molto complicata da usare (mstrVLT).
Grazie a chiunque possa aiutarmi.
Titolo: Re:Telegram Bot
Inserito da: Stilgar - Dicembre 01, 2017, 04:29:35 pm
Questa?
https://github.com/MstrVLT/TGBotLazarus
Titolo: Re:Telegram Bot
Inserito da: xinyiman - Dicembre 01, 2017, 04:33:25 pm
Ciao clayrm, se posso chiederti che funzionalità pensi di implementare?
Titolo: Re:Telegram Bot
Inserito da: Stilgar - Dicembre 01, 2017, 04:47:18 pm
Non mi risulta chiaro cosa ti è ostico in quella libreria.
Quella che hai menzionata non si capisce se è portata avanti o meno.
Cmq.
"Cation! Library is forked to https://github.com/Al-Muhandis/fp-telegram This project is in development. If you want to join us write in telegram @mstrVLT. It is still unfinished library, but You can use it in your own working projects"


Dello stesso autore:
https://github.com/Al-Muhandis/brook-telegram

 
Titolo: Re:Telegram Bot
Inserito da: clayrm - Dicembre 01, 2017, 04:56:50 pm
Si queste sono quelle che avevo trovato anche io. Per le mie competenze le trovo un po complicate. In python bastava creare l'oggeto e con una chiamata a oggetto.message partiva un thread che ti mandava le risposte dal server. Davvero due righe di programma. Comunque cercherò di approfondire queste consigliate.
In pratica sto utilizzando Lazarus su raspberry, e vorrei fare una unit che gestisca l'invio e ricezione di comandi via Telegram. Spero di essere stato chiaro.
Grazie comunque a tutti.
Titolo: Re:Telegram Bot
Inserito da: Stilgar - Dicembre 01, 2017, 05:00:18 pm
:)
Codice: [Seleziona]

  { TMyAction }

  TMyAction = class(TWebhookAction)
  public
    constructor Create(ARequest: TBrookRequest; AResponse: TBrookResponse); overload;
      override;
    procedure Post; override;
  end;


Stando alla descrizione della libreria devi modificare qui dentro le configurazioni per poter puntare al tuo bot.

Codice: [Seleziona]

constructor TMyAction.Create(ARequest: TBrookRequest; AResponse: TBrookResponse
  );
begin
  inherited Create(ARequest, AResponse);
  { This isnt real telegram token! Please get token from
  https://core.telegram.org/bots#botfather }
  Token:='123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11';
  StartText:='Hi! It is simplest HelloBot based on brookframeork and TGBotLazarus!';
  HelpText:='This help text for the bot...';
  { Please enter XXXXXX - [your ]user ID (integer value) for availabality of
  admin commands (/stat, /statf /terminate)}
  UserPermissions.Add('XXXXXX=a');
  { You can do not create this log. If its value is nil,
  then the logging just will not be maintained }
  StatLogger.Paused:=False; // run statistics log
  Logger:=BLogger;
end;



Per il resto è un'applicazione basata su Brook.
;) NoMore ... qui sei più bravo tu
Titolo: Re:Telegram Bot
Inserito da: clayrm - Dicembre 01, 2017, 05:17:04 pm
Si stavo giusto vedendo.
Grazie ancora Stilgard.
Ma quale bravo... semplice autodidatta.
Buon fine settimana!
Titolo: Re:Telegram Bot
Inserito da: Stilgar - Dicembre 01, 2017, 05:19:06 pm
:) Nomore -> nomorelogic
Titolo: Re:Telegram Bot
Inserito da: bonmario - Giugno 08, 2018, 04:14:09 pm
Ciao a tutti,
ho scaricato i sorgenti da qui: https://github.com/Al-Muhandis/fp-telegram

Ho provato a fare girare il progetto di esempio "getMe", impostando il token di un bot creato da me, e funziona.
Il problema è che non ho capito come si usa ....

La mia esigenza è, almeno spero, abbastanza semplice: dovrei solo mandare un messaggio su quel bot creato da me, non mi interessa ricevere e/o gestire risposte.
E' da ieri sera che ci sto provando, ma non ci sono ancora riuscito.

Qualcuno mi sa dare una dritta o un programmino di esempio?

P.S. Non ho provato a scaricare l'altro, quello del framework Brook, perché vorrei fare il tutto usando meno componenti possibile.


Questo è quello che ho provato io:
Codice: [Seleziona]
  WrkBot:=TTelegramSender.Create(CstTokenNewsGandiniLodiBot);
  try
    WrkBot.sendMessage('Prova');
  finally
    FreeAndNil(WrkBot);
  end;

Il risultato è questo errore:
Codice: [Seleziona]
{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}

Grazie in anticipo, Mario
Titolo: Re:Telegram Bot
Inserito da: bonmario - Giugno 08, 2018, 07:45:01 pm
CAsomai servisse ad altri in futuro, ci sono riuscito così:

Codice: [Seleziona]
function  InviaMsgBot(TestoMessaggio:String):Boolean;
var WrkBot: TTelegramSender;
begin
  Result:=False;

  WrkBot:=TTelegramSender.Create(CstTokenNewsGandiniLodiBot);
  try
    if WrkBot.getMe then begin
      WrkBot.getUpdates();
      if WrkBot.sendMessage(WrkBot.CurrentChatId, '/start') then begin
        if WrkBot.sendMessage(WrkBot.CurrentChatId, TestoMessaggio) then begin
          Result:=True;
        end;
      end;
    end;
  finally
    bmt_LastErrorDescription:=WrkBot.LastErrorDescription;
    bmt_LasterrorCode:=WrkBot.LastErrorCode;

    FreeAndNil(WrkBot);
  end;
end;

Devo però capire perché, delle 3 persone che usano il bot, solo 2 ricevono i messaggi che invio ...

Ciao, Mario
Titolo: Re:Telegram Bot
Inserito da: bonmario - Luglio 05, 2018, 11:34:43 am
Come non detto ... la cosa a volte funziona ed a volte no, ma non ne ho ancora capito il motivo.
La discussione prosegue anche sul forum inglese, a questo indirizzo: http://forum.lazarus.freepascal.org/index.php/topic,38959.msg290055.html#msg290055

Ciao, Mario