Telegram

Telegram

Postby Silvio.Falconi » Wed Sep 19, 2018 11:53 am

exist some method to send sms or small message on telegram from fivewin ?
Can see any easy sample ?

for telegram I found ( some one can help me )
https://core.telegram.org/mtproto
https://core.telegram.org/api
https://telegram.org/apps#source-code

there is also a lib to use with c++
https://core.telegram.org/tdlib
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Telegram

Postby cnavarro » Wed Sep 19, 2018 2:20 pm

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Telegram

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

I tried it only not found token and chatid
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Telegram

Postby dagiayunus » Thu Sep 20, 2018 8:26 am

Silvio.Falconi wrote:I tried it only not found token and chatid


Dear Mr.Silvio

check the following link for how to get telegram token
https://www.siteguarding.com/en/how-to- ... -api-token

viewtopic.php?f=3&t=33056&start=0

Regards
Yunus
Regards
Yunus

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

Re: Telegram

Postby Silvio.Falconi » Thu Sep 20, 2018 10:54 am

Yunus,

I create mybot and I have token
now it want chat_id where i take this ?
then I compiled the prg into viewtopic.php?f=3&t=33056&start=0#p194671
it is compiled and not happen nothing
it not open any htpp

I have this ( on word mytoken I copied my token)

and then I not understtod how send a msg

Code: Select all  Expand view  RUN

#include "fivewin.ch"

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
    local cTOKEN:= "mytoken"
   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




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:= "mytoken"
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


 




as you can see here I Instal telegram for window and I open it
then I compiled your test and not happened nothig

Image
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: 7090
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: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Telegram

Postby dagiayunus » Thu Sep 20, 2018 3:12 pm

Silvio.Falconi wrote:Yunus,

I create mybot and I have token
now it want chat_id where i take this ?
then I compiled the prg into viewtopic.php?f=3&t=33056&start=0#p194671
it is compiled and not happen nothing
it not open any htpp

I have this ( on word mytoken I copied my token)

and then I not understtod how send a msg

Code: Select all  Expand view  RUN

#include "fivewin.ch"

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
    local cTOKEN:= "mytoken"
   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') [color=#FF0000]When someone send msg to your telegram bot than you cn get the chat id.[/color]

      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




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:= "mytoken"
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


 




as you can see here I Instal telegram for window and I open it
then I compiled your test and not happened nothig

Image

to retrieve chat id first you have to send some text msg to your bot using telegram
(after sending text msg using telegram in your browser type
https://api.telegram.org/botcTOKEN/getUpdates )

viewtopic.php?f=3&t=33056&start=0#p194671

for further details you may contact me on dagiayuns at gmail.com
Regards
Yunus

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

Re: Telegram

Postby Silvio.Falconi » Thu Sep 20, 2018 5:47 pm

yunus,

your email no exist
send me a message at silvio[dot]falconi[at]gmail[dot]com thanks
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Telegram

Postby Silvio.Falconi » Thu Sep 20, 2018 5:55 pm

Dear my Friend,

I wish understood it telegram can be usefull for my work

I work at school and I have an application where I need to send a message to some teachers

type " 5TC 3ora Rec Bitti "

Well I say you what I made

I Installed telegram on windows and I have also the portable version

I put the portable version on c:\work\errori\Telegram\Telegram

At installation it ask me a number of my phone and a verify number

then I set on setup to luch telegram at init when the system ( pc) is open

your test compiled is on c:\work\errori\telegram (test.exe)

you sad I need ctoken and chat id

On telegram I open botfather and I create a new bot sample @sost_bot

then I ask the token and it gave me the token and I copied on your test

then I link to Falcongate and I write /get_my_id and I have the id( number)


I insert token and id on your test

cToken := ""

cChat_id := ""

ctoken from botfather

cChat_id from falcongate

I run your test and it ask me a message and when I click to button "Enviar"

it return this error

404 not found

I tried with
LOCAL cToken := "", cChat_id := "@sost_bot"

it return - 404 error bad request

where I wrong ?

Questions

To send a message to all my teacher from fwh what I need ?

I need the number of phones or the his Id ?

if i need the id, How I can make to Know the number of id of each teacher ?


I hope your help

Best Regards
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Telegram

Postby Silvio.Falconi » Thu Sep 20, 2018 7:03 pm

Now I create a new bot FROM BOTFATHER and take the token
then I take my id from falcongate with /get-my_id

I insert the token and chat_id into test.prg (fwh)


When I sent message on this bot the test make this message

Image

and then insert the message on bot



Image


It run from fwh but I have some questions


1. I can create a group and link to bot and insert all techers into but each teachers read the message I sent to bot - no good

2. I wish send the message only directly to each teacher no pubblic

how I can resolve ?
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Telegram

Postby Silvio.Falconi » Fri Sep 21, 2018 12:18 am

I resolved!
the problem was it cannot be a GET but a POST
It run with personal chatid and also with Group
I need to Know if I can send message to one teacher and to all teacher ( are in a Group)
the problem was I not Know the Id of all teacher and the mode more easy was that to send message to a Group where are all teachers
the group can be normal group where all member are administrators and supergroup where you decide who is the administrator and you decide who can talk
all member listen
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: 7090
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests