Jump to content
Fivewin Brasil

telegram


sistem

Recommended Posts

#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


 

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...