Page 1 of 1

telegram

PostPosted: Fri Aug 10, 2018 11:34 am
by Sistem
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

Re: telegram

PostPosted: Fri Aug 10, 2018 1:34 pm
by karinha
Code: Select all  Expand view

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

Re: telegram

PostPosted: Fri Aug 10, 2018 1:54 pm
by karinha
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
 

Re: telegram

PostPosted: Tue Aug 14, 2018 1:02 pm
by Sistem
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"

Re: telegram

PostPosted: Tue Aug 14, 2018 1:12 pm
by karinha
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".

Re: telegram

PostPosted: Tue Aug 14, 2018 2:30 pm
by Sistem
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

Re: telegram

PostPosted: Wed Sep 19, 2018 2:53 pm
by Silvio.Falconi
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 ?

Re: telegram

PostPosted: Thu Sep 20, 2018 12:56 pm
by karinha