1

i wanted to create my bot in VBScript (i know its like troll and bad idea probably, i can do it in lua, python, C#, PHP, ...., but i decided to try and make it from vbscript) the hard part is that i'm trying to Retrieve information from Telegram getUpdates

i've made this code for example and it kind of works, i'll explain what works and what doesn't

Dim fso, outFile, TeleTest
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set outFile = fso.CreateTextFile("output.txt", True)
    set TeleTest = fso.CreateTextFile("TeleTest.txt", True)

    Dim url, req, json
    Set req = CreateObject("MSXML2.XMLHTTP")

    url = "https://api.telegram.org/bot"[TOKEN]"/getUpdates"

    req.open "GET", url, False
    req.send

    If req.Status = 200 Then
      TeleTest.Write req.responseText
    End If
    '  Load the JSON array into a JsonArray:
    set jsonArray = CreateObject("Chilkat_9_5_0.JsonArray")
    success = jsonArray.Load("TeleTest.txt")
    If (success <> 1) Then
        outFile.WriteLine(jsonArray.LastErrorText)
        WScript.Quit
    End If

    '  Get some information from each record in the array.
    numRecords = jsonArray.Size
i = 0
Do While i < numRecords
    outFile.WriteLine("------ Record " & i & " -------")

    ' jsonRecord is a Chilkat_9_5_0.JsonObject
    Set jsonRecord = jsonArray.ObjectAt(i)
 outFile.WriteLine("  ok: " & jsonRecord.StringOf("ok"))
 outFile.WriteLine("  result: " & jsonRecord.SizeOfArray("result"))

    '  Examine information for this record
 u = 0
    Do While u < nummessage
    nummessage = jsonRecord.SizeOfArray("result[u].message")
 Loop
    outFile.WriteLine("Number of message: " & nummessage)
    j = 0
    Do While j < nummessage
        jsonRecord.J = j
        outFile.WriteLine("  message text: " & jsonRecord.StringOf("result[j].message[j].text"))
        j = j + 1
    Loop
    i = i + 1
Loop
    outFile.Close

so the first part that should get updates and save it ino TeleTest.txt works fine, it gets updates, it saves the json in to the .txt file (or anything, i can also save it into string in the vbs, or .json file)

the problem is that the second part where i'm using Chilkat gives error

Blockquote ChilkatLog: Load: ChilkatVersion: 9.5.0.78 Unable to get array at index 0. --Load --ChilkatLog

any help or any idea would be appereciated, also if Chilkat is not good for doing this, maybe tell me why and give me something else?! (Chilkat was the only dll i found to work with vbscript and does json reading, stuff)

1 Answers1

1

i got it to working, i found out that from this example Chilkat needs the Json file to like this

[ { json } ]

but the Telegram json is like this

{ json }

so, the fix would be easy to just change line 15 from TeleTest.Write req.responseText to this code below

TeleTest.Write "[" + req.responseText + "]"

my code now works fine , if anyone else found something wrong or any answer to my question it would be appreciated i hope someone else who needs this find this