[Gambas-user] Request for advice
John Dovey
dovey.john at gmail.com
Mon Jul 12 19:25:33 CEST 2021
I am working on wrapping theTelegram bot API in Gambas (as recommended
here before) but I'm not sure of a few things in the best approach.
For example, the simplest call to the API is to get info about the
bot. This looks like this:
public Token as string = "xxx"
Public apiURL As String = "https://api.telegram.org/bot" & Token & "/"
Public hClient As HttpClient
Public sBuffer As String
Public cmdResponse As String
Public cmdJSON As Collection
Public Sub Main()
getBotMe
End
Public Sub getBotMe()
hClient = New HttpClient As "hClient"
hClient.URL = apiURL & "getMe"
hClient.Async = False
hClient.Timeout = 60
hClient.Get
Print "Begin"
If hClient.Status < 0 Then
Print "ERROR"
Else
' Success - read the data
If Lof(hClient) Then sBuffer = Read #hClient, Lof(hClient)
Print sBuffer
cmdResponse = sBuffer
End If
cmdJSON = JSON.Decode(cmdResponse)
botMe = cmdJSON["result"]
Print "End"
End
Some of the questions I have include:
- does this make sense as a way to do this?
- What is the best way to store the returned collection? I thought
about usingSTRUCT, but there is a prettyheavy warning in the wiki not
to do so.
The BotMe info is in the attached image:
JD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 14974 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210712/70b9e96a/attachment-0001.png>
More information about the User
mailing list