Jump to content

Recommended Posts

  • Developers

Just tested with the latest version and don't see that issue. Could you open telegram.au3 and uncomment line 791, so it will display the received text?

Func _Polling()
    While 1
        Sleep(1000) ;Prevent CPU Overloading
        $newUpdates = _GetUpdates()
        ConsoleWrite($newUpdates & @CRLF)
        If Not StringInStr($newUpdates,'update_id') Then ContinueLoop
        $msgData = __MsgDecode($newUpdates)
        $OFFSET = $msgData[0] + 1
        ;ConsoleWrite(_ArrayToString($msgData) & @CRLF)
        Return $msgData
    WEnd
EndFunc ;==> _Polling

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

13 minutes ago, Jos said:

Could you open telegram.au3 and uncomment line 791, so it will display the received text?

Sure. Here's what I got (changed the numbers and names):

{"ok":true,"result":[{"update_id":3047043522550647,
"my_chat_member":{"chat":{"id":-81145169345617,"title":"GroupName","type":"group","all_members_are_administrators":true},"from":{"id":316898134589,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"date":1671734534514725,"old_chat_member":{"user":{"id":5951434506661,"is_bot":true,"first_name":"BotName","username":"BotUsername"},"status":"left"},"new_chat_member":{"user":{"id":595134535406661,"is_bot":true,"first_name":"BotName","username":"BotUsername"},"status":"member"}}},{"update_id":30345470099648,
"message":{"message_id":23,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":-81116960017,"title":"Prescott Norris Office","type":"group","all_members_are_administrators":true},"date":1671713454725,"group_chat_created":true}},{"update_id":30470070649,
"message":{"message_id":24,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1634571714973,"text":"hey"}},{"update_id":30478000650,
"message":{"message_id":25,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1673451716039,"text":"hey"}},{"update_id":30479000651,
"message":{"message_id":26,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671456716336,"text":"test"}},{"update_id":30504700652,
"message":{"message_id":27,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671789717549,"text":"test"}},{"update_id":30479000653,
"message":{"message_id":28,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1123671717640,"text":"test"}},{"update_id":30456700654,
"message":{"message_id":29,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671717678652,"text":"check"}},{"update_id":33404700655,
"message":{"message_id":30,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671789017960,"text":"Hey"}},{"update_id":30470088656,
"message":{"message_id":31,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671890718156,"text":"Check"}}]}

 

Link to comment
Share on other sites

  • Developers

Thanks... I had a play with your received data and the issue is with the first message which isn't properly handled by this UDF, so gets stuck there. This also explains why the posted work-around is fixing it as long as there isn't another message of that type.

Guess this needs to be fixed by the original owner of the UDF so you best report it at the GITHUB.

.. and the quick fix should be those 4 steps you earlier quoted, as that should skip this messages.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

5 minutes ago, Jos said:

so you best report it at the GITHUB

Sure thing, I'll do that. In the meantime I'll try out the libcurl version posted here:

Could you tell me where I should put the libcurl DLL files? Should they be in path or can I set their location using a global variable in the UDF?

Link to comment
Share on other sites

  • Developers

Try replacing func __MsgDecode() with this version first as that will likely solve it for you:

Func __MsgDecode($Update)
    Local $json = Json_Decode($Update)

    ;@PRIVATE CHAT MESSAGE

    If (Json_Get($json, '[result][0][message][chat][type]') = 'private') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _
                Json_Get($json, '[result][0][message][message_id]'), _
                Json_Get($json, '[result][0][message][from][id]'), _
                Json_Get($json, '[result][0][message][from][username]'), _
                Json_Get($json, '[result][0][message][from][first_name]') _
                ]

        If (Json_Get($json, '[result][0][message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][message][text]')

        ; TODO: Media recognition

        Return $msgData

        ;@GROUP CHAT MESSAGE (Inlude left/new member events)
    ElseIf (Json_Get($json, '[result][0][message][chat][type]') = 'group') Or (Json_Get($json, '[result][0][message][chat][type]') = 'supergroup') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][message][from][id]'), _ ;[2] = User ID
                Json_Get($json, '[result][0][message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][message][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][message][chat][id]'), _ ;[5] = Group ID
                Json_Get($json, '[result][0][message][chat][title]') _ ;[6] = Group Name
                ]

        If (Json_Get($json, '[result][0][message][left_chat_member]')) Then
            $msgData[7] = 'left' ;[7] = Event
            $msgData[8] = Json_Get($json, '[result][0][message][from][id]') ;[8] = Left member ID
            $msgData[9] = Json_Get($json, '[result][0][message][from][username]') ;[9] = Left member Username
            $msgData[10] = Json_Get($json, '[result][0][message][from][first_name]') ;[10] = Left member Firstname
        ElseIf (Json_Get($json, '[result][0][message][new_chat_member]')) Then
            $msgData[7] = 'new' ;[7] = Event
            $msgData[8] = Json_Get($json, '[result][0][message][from][id]') ;[8] = New member ID
            $msgData[9] = Json_Get($json, '[result][0][message][from][username]') ;[9] = New member Username
            $msgData[10] = Json_Get($json, '[result][0][message][from][first_name]') ;[10] = New member Firstname
        Else
            $msgData[7] = Json_Get($json, '[result][0][message][text]') ;[7] = Text
        EndIf

        Return $msgData

        ;@EDITED PRIVATE CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_message][chat][type]') = 'private') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_message][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_message][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_message][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

        ;@EDITED GROUP CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_message][chat][type]') = 'group') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_message][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_message][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_message][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

        ;@CALLBACK QUERY
    ElseIf (Json_Get($json, '[result][0][callback_query][id]') <> '') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][callback_query][id]'), _ ;[1] = Callback ID
                Json_Get($json, '[result][0][callback_query][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][callback_query][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][callback_query][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][callback_query][data]') _ ;[5] = Callback Data
                ]

        Return $msgData

        ;@INLINE QUERY
    ElseIf (Json_Get($json, '[result][0][inline_query][id]') <> '') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][inline_query][id]'), _ ;[1] = Inline Query ID
                Json_Get($json, '[result][0][inline_query][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][inline_query][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][inline_query][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][inline_query][query]') _ ;[5] = Inline Query Data
                ]

        Return $msgData

        ;@CHANNEL MESSAGE (Where bot is admin)
        ; Sample JSON:
        #comments-start
            {"ok":true,"result":[{
                "update_id":<int>,
                "channel_post":{
                    "message_id":<int>,
                    "chat":{
                    "id":<int>,
                    "title":"<string>",
                    "type":"channel"},
                    "date":<int>,
                    "text":"<string>"
            }}]}
        #comments-end
    ElseIf (Json_Get($json, '[result][0][channel_post][message_id]') <> '') Then
        Local $msgData[5] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][channel_post][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][channel_post][chat][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][channel_post][chat][title]') _ ;[3] = Firstname
                ]

        If (Json_Get($json, '[result][0][channel_post][text]')) Then
            $msgData[4] = Json_Get($json, '[result][0][channel_post][text]') ;[4] = Text (eventually)
        EndIf

        Return $msgData

        ;@EDITED CHANNEL CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_channel_post][chat][type]') = 'channel') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_channel_post][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_channel_post][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_channel_post][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_channel_post][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_channel_post][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_channel_post][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData
        ;@EDITED CHANNEL CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][my_chat_member][chat][type]') = 'group') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][my_chat_member][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][my_chat_member][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][my_chat_member][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][my_chat_member][from][first_name]') _ ;[4] = Firstname
                ]
        $msgData[5] = ""
        If (Json_Get($json, '[result][0][my_chat_member][text]')) Then $msgData[5] = Json_Get($json, '[result][0][my_chat_member][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

    EndIf

EndFunc   ;==>__MsgDecode

 

20 minutes ago, noellarkin said:

Could you tell me where I should put the libcurl DLL files? Should they be in path or can I set their location using a global variable in the UDF?

Looks to me you need to add that Curl UDF which is linked in that post. 
The Telegram.au3 in that version looks somewhat more ridged 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, Jos said:

Try replacing func __MsgDecode() with this version first as that will likely solve it for you:

Thank you, this worked! For any forum members who may stumble upon this thread, this is a solution to the the error:

Line 794 in Telegram.au3
$OFFSET = $msgData[0] + 1
$OFFSET = $msgData^ERROR
Error: Subscript used on non-accessible variable

 

 

1 hour ago, Jos said:

Looks to me you need to add that Curl UDF which is linked in that post. 

I did, I unpacked all the files in Curl UDF to the Include folder. I also went ahead and copied the two provided dll files in the same directory as the example script (Test.au3) as well as in a folder accessible to PATH. I'm still getting "Error opening libcurl.dll" Is there any way I can set the full path in the UDF?
Furthermore, I'm getting:
image.png.44d564efd252d75cb1fdc5bf35032564.png

as well as:
image.png.f36df999dc6c912be455b94b13dff3e6.png

 

when attempting to run "Test.au3" (example file provided in the LibCurl Telegram Bot UDF).

Link to comment
Share on other sites

  • 3 weeks later...
On 12/22/2022 at 2:28 PM, noellarkin said:

Tried the original UDF (downloaded from the github link in the first post), with the example script provided:

 

#include "../src/Telegram.au3"

HotKeySet("{PAUSE}","_Exit") ;Press 'PAUSE' on your keyboard to force-exit the script

$Token = "I put my token here" ;Token here
_InitBot($Token)

While 1
    $msgData = _Polling()
    ConsoleWrite("Incoming message from " & $msgData[3] & ": " & $msgData[5] & @CRLF)
    _SendMsg($msgData[2],$msgData[5])
WEnd

Func _Exit()
    Exit 0
EndFunc


Getting the error:
Line 794 in Telegram.au3

$OFFSET = $msgData[0] + 1

$OFFSET = $msgData^ERROR

Error: Subscript used on non-accessible variable

There were enough issues with the original UDF, not only this but also other false interpretations taken from the Telegram API that made this UDF not really reliable.
Not all the fault of the designer, the API chronological behavior wasn't all too clear either.

Link to comment
Share on other sites

  • 3 weeks later...

An apology, use google translate to change to English

I have tried the code and it works perfectly, message, photo, audio, document, voice, sticker.

I just don't see how to send a message to a telegram group or channel. Has anyone already done it?

 

Aca en español

Una disculpa, use google traductor para cambiar a ingles

He probaro el codigo y funciona a la perfeccion, mensaje, foto, audio, documento, voz, sticker. 

Solo que no veo como enviar un mensaje a un grupo o canal de telegram. Alguien ya lo logro?

Link to comment
Share on other sites

Just now, jkarlos said:

An apology, use google translate to change to English

I have tried the code and it works perfectly, message, photo, audio, document, voice, sticker.

I just don't see how to send a message to a telegram group or channel. Has anyone already done it?

 

Aca en español

Una disculpa, use google traductor para cambiar a ingles

He probaro el codigo y funciona a la perfeccion, mensaje, foto, audio, documento, voz, sticker. 

Solo que no veo como enviar un mensaje a un grupo o canal de telegram. Alguien ya lo logro?

#include "../src/Telegram.au3"
#include <Array.au3>

;~ ConsoleWrite("Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit)." & @CRLF & _
;~              "This file need a valid ChatID of a Telegram user who has already sent at least a message to the bot, and a valid token given by @BotFather." & @CRLF & _
;~              "Insert this data in the source code." & @CRLF & @CRLF)

Local $ChatID = '### id' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = 'Token' ;Token here

;~ If(($ChatID = '') or ($Token = '')) Then
;~     ConsoleWrite("Warning! ChatID or Token not specified!")
;~     Exit -1
;~  EndIf
_InitBot($Token)
Local $myData = _GetMe()

$MsgID = _SendMsg($ChatID,"Hola, esto es una prueba")

 

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...