telegram

telegram

Postby Sistem » Fri Aug 10, 2018 11:34 am

envio de msg para bot telegram
veja o video para entender melhor:
https://www.youtube.com/watch?v=hJBYojK7DO4
Code: Select all  Expand view

Function Telegram()
 Local oDlg, oFont, oFont2, lEnvia:=.f., cMsg:=Space(500), cUrl, aArray, oHost, oBtn, oSay, x1
 Local cToken := "AQUI COLOQUE SEU TOKEN", cChat_id := "AQUI CHAT ID"
 Local xMsg := "*AQUI SUA MSG*%0A"+;
               "MAIS MSG%0A"

  DEFINE FONT oFont  NAME "Lucida Console" SIZE 0,-14
  DEFINE FONT oFont2 NAME "Lucida Console" SIZE 0,-10

  DEFINE DIALOG oDlg FROM 4, 4 TO 8, 90 TITLE "msg p/bot Telegram"

  @  4,  6 GET oMsg VAR cMsg PIXEL OF oDlg COLOR CLR_GET1,CLR_GET2 SIZE 290, 16 FONT oFont CUEBANNER "Sua mensagem aqui"

  @ 4, 300 BUTTON "Enviar" PIXEL OF oDlg SIZE 34, 16 ACTION (lEnvia:=.t., oDlg:End())

  oDlg:lHelpIcon := .f.

 ACTIVATE DIALOG oDlg CENTERED ON INIT oBtn:SetFocus()

  If lEnvia .and. !Empty(cMsg)
     cUrl := "https://api.telegram.org/bot"+cToken+"/sendMessage?chat_id="+cChat_id+"&parse_mode=Markdown&text="+xMsg+cMsg
     Try
         oHost := CreateObject( 'MSXML2.ServerXMLHTTP.6.0' )
     Catch erro
         ? erro:Description
         return nil
     End

     oHost:open('GET', cUrl, .f.)
     oHost:send()

     If oHost:Status != 200
        MsgStop(Alltrim(STR(oHost:Status))+" - "+oHost:StatusText , "Erro")
        Return nil
     Endif

     While oHost:readyState != 4
        oHost:WaitForResponse(1000)
     End

     x1 := hb_jsondecode( oHost:responseText, @aArray )

     If aArray == nil
         MsgStop("Erro ao retornar os dados. Tente novamente.")
         Return nil
     Endif

     If aArray['ok'] = .f.
       MsgStop("Erro no envio da messagem.", "Aviso!")
     Else
       MsgInfo("Sucesso no envio da messagem.", "Aviso!")
     Endif
  Endif

Return nil
 



telegram canais fivewin:
(fivewin brasil) => https://t.me/fivewinbr
(fivewin internacional) => https://t.me/fivewines
FWH2008 | xHarbour | BCC74 | SQLRDD
User avatar
Sistem
 
Posts: 226
Joined: Sun May 13, 2012 7:52 am

Re: telegram

Postby karinha » Fri Aug 10, 2018 1:34 pm

Code: Select all  Expand view

   ON INIT oBtn:SetFocus()  // ???
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: telegram

Postby karinha » Fri Aug 10, 2018 1:54 pm

Code: Select all  Expand view

#include "FiveWin.ch"

#Define CLR_GET1 CLR_BLACK
#Define CLR_GET2 CLR_WHITE

FUNCTION Telegram()

   LOCAL oDlg, oFont, oFont2, lEnvia := .F. , cMsg := Space( 500 ), cUrl, ;
         aArray, oHost, oBtn, oSay, x1
   LOCAL cToken := "AQUI COLOQUE SEU TOKEN", cChat_id := "AQUI CHAT ID"
   LOCAL xMsg := "*AQUI SUA MSG*%0A" + ;
                 "MAIS MSG%0A"
   LOCAL oMsg, Erro

   DEFINE FONT oFont  NAME "Lucida Console" SIZE 0, - 14
   DEFINE FONT oFont2 NAME "Lucida Console" SIZE 0, - 10

   DEFINE DIALOG oDlg FROM 4, 4 TO 8, 90 TITLE "msg para bot Telegram" ;
          COLOR CLR_BLACK, CLR_WHITE TRANSPARENT

   oDlg:lHelpIcon := .F.

   Set( _SET_INSERT, ! Set( _SET_INSERT ) )

   @  4,  6 GET oMsg VAR cMsg PIXEL OF oDlg COLOR CLR_GET1, CLR_GET2 ;
      SIZE 290, 16 FONT oFont CUEBANNER "Sua mensagem aqui"

   @ 4, 300 BUTTON oBtn PROMPT( "Enviar" ) PIXEL OF oDlg SIZE 34, 16 ;
      ACTION ( lEnvia := .T. , oDlg:End() ) CANCEL

   ACTIVATE DIALOG oDlg CENTERED ON INIT oMsg:SetFocus() //oBtn:SetFocus()

   Set( _SET_INSERT, ! Set( _SET_INSERT ) )

   oFont:End()
   oFont2:End()

   IF lEnvia .AND. !Empty( cMsg )

      cUrl := "https://api.telegram.org/bot" + cToken + "/sendMessage?chat_id=" + cChat_id + "&parse_mode=Markdown&text=" + xMsg + cMsg

      Try
         oHost := CreateObject( 'MSXML2.ServerXMLHTTP.6.0' )
      Catch erro
         ? erro:Description
         RETURN nil
      End

      oHost:open( 'GET', cUrl, .F. )
      oHost:send()

      IF oHost:Status != 200
         MsgStop( Alltrim( STR(oHost:Status ) ) + " - " + oHost:StatusText , "Erro" )
         RETURN nil
      ENDIF

      WHILE oHost:readyState != 4
         oHost:WaitForResponse( 1000 )
      End

      x1 := hb_jsondecode( oHost:responseText, @aArray )

      IF aArray == nil
         MsgStop( "Erro ao retornar os dados. Tente novamente." )
         RETURN nil
      ENDIF

      IF aArray['ok'] = .F.
         MsgStop( "Erro no envio da messagem.", "Aviso!" )
      ELSE
         MsgInfo( "Sucesso no envio da messagem.", "Aviso!" )
      ENDIF

   ENDIF

RETURN nil
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: telegram

Postby Sistem » Tue Aug 14, 2018 1:02 pm

karinha wrote:
Code: Select all  Expand view

   ON INIT oBtn:SetFocus()  // ???
 

olá amigo karinha usei o oBtn:SetFocus() por causa do CUEBANNER "Sua mensagem aqui"
FWH2008 | xHarbour | BCC74 | SQLRDD
User avatar
Sistem
 
Posts: 226
Joined: Sun May 13, 2012 7:52 am

Re: telegram

Postby karinha » Tue Aug 14, 2018 1:12 pm

Sistem wrote:
karinha wrote:
Code: Select all  Expand view

   ON INIT oBtn:SetFocus()  // ???
 

olá amigo karinha usei o oBtn:SetFocus() por causa do CUEBANNER "Sua mensagem aqui"


My dear friend, o objeto oBtn, não existe em local algum. Saudações. Gera erro na compilação.

Você pode usar o cToolTip para: "Sua mensagem aqui".
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: telegram

Postby Sistem » Tue Aug 14, 2018 2:30 pm

tem razao
e que para simplificar apaguei o codigo errado:
If oApp:lBtn2007
@ 4, 300 BTNBMP oBtn OF oDlg SIZE 34, 16 PIXEL 2007 NOBORDER PROMPT "Enviar" LEFT RESOURCE "BMP_BTOK" ACTION (lEnvia:=.t., oDlg:End())
Else
@ 4, 300 BUTTON "Enviar" PIXEL OF oDlg SIZE 34, 16 ACTION (lEnvia:=.t., oDlg:End())
Endif
FWH2008 | xHarbour | BCC74 | SQLRDD
User avatar
Sistem
 
Posts: 226
Joined: Sun May 13, 2012 7:52 am

Re: telegram

Postby Silvio.Falconi » Wed Sep 19, 2018 2:53 pm

Please a question

Code: Select all  Expand view
Local cToken := "AQUI COLOQUE SEU TOKEN", cChat_id := "AQUI CHAT ID"


where I can found token ?

then where is chat ID ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6849
Joined: Thu Oct 18, 2012 7:17 pm

Re: telegram

Postby karinha » Thu Sep 20, 2018 12:56 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 37 guests