TELEGRAM with FIVEWIN (Tutorial)

TELEGRAM with FIVEWIN (Tutorial)

Postby dagiayunus » Thu Oct 13, 2016 3:36 pm

Dear Sir,

Thanks to Mr. Antonio to encourage to write the application.

1. install TELEGRAM (message application like whatsapp) and setup
2. talk with botfather and create bot and write down the TOKEN
https://telegram.me/BotFather
http://botsfortelegram.com/project/the-bot-father/

Now send few text msg to your BOT using your mobile.

Below is the example to retrive messages

Code: Select all  Expand view
function Main()  

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
   local cTOKEN:= "Paste your TOKEN here"
   local URL:="https://api.telegram.org/bot"+cTOKEN+"/getUpdates"

   ohttp:Open( "POST" ,URL, .F. )
   oHttp:SetRequestHeader("Accept" ,"application/xml")
   oHttp:SetRequestHeader("Content-Type","application/json")
   oDoc:async:=.f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   oHttp:Send(oDoc:xml)
   
   cText:=Alltrim(oHttp:responseText)
   cText=strtran(cText,'{"ok":true,"result":[','')
   cText=alltrim(cTExt)

   ar:=HB_ATOKENS( cTEXT, '{"update_id":' )  // split json string to array

 
 
 for i=2 to len(ar)
      x:=ar[i]
      nUpdateId:=GetUpdateId(x)
      ?nUpdateId, "Message_id",ExtractValue(x,"message_id"),"From_Id",ExtractValue(x,'from":{"id'),"Chat_Id",ExtractValue(x,'"chat":{"id')
      fName:=ExtractValue(x,"first_name")
      fname:=strTran(fname,'}','')
      ?fname
      ?GetMsg(x)
   
 next i

return nil

function ExtractValue(x,srchValue)

return SubStr( x, nAt := At( srchValue, x ) + Len( srchValue )+2, At( ",", SubStr( x, nAt  ))-1)
//?SubStr( x, nAt := At( "message_id", x ) + Len( "message_id" )+2, At( ",", SubStr( x, nAt + Len( "message_id" ) )) -1 )


function GetUpdateId(x)
substr(x,1,at(",",x)-1)

function Getmsg(x)
cMsg:=RIGHT(x,LEN(x) - RAT(":", x) - 1)
cMsG:=substr(cMsg,1,rat('"',cMsg)-1)
return cMsg






 
Regards
Yunus

FWH 21.02
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm

Re: TELEGRAM with FIVEWIN (Tutorial)

Postby vilian » Fri Oct 14, 2016 11:02 am

Thanks,

Is there a sample how-to send message with this?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 977
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: TELEGRAM with FIVEWIN (How to Send Msg) Tutorial)

Postby dagiayunus » Fri Oct 14, 2016 1:28 pm

Dear Vilian

Here is a example how to send message

Code: Select all  Expand view
function sendmsg(cChatId,cMsg)  // CHAT_ID how to get chat_id please look my first post
local odoc  := CreateObject( "MSXML2.DOMDocument" )
local ohttp := CreateObject( "MSXML2.XMLHTTP" )
local cTOKEN:="YOUR TOKEN HERE"
ohttp:Open( "POST" ,"https://api.telegram.org/bot"+cTOKEN+"/sendMessage?text="+cMsg+"&chat_id="+cChatId+'"', .F. )
ohttp:SetRequestHeader( "Accept"        , "application/xml")
ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
oDoc:async := .f.
oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
ohttp:Send(oDoc:xml)
oDoc:=Nil
return nil
 


Thanks & Regards
Yunus
Regards
Yunus

FWH 21.02
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm

Re: TELEGRAM with FIVEWIN (Tutorial)

Postby vilian » Fri Oct 14, 2016 2:53 pm

Thank you very much.
User avatar
vilian
 
Posts: 977
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests