Line 794 [in](https://www.autoitscript.com/autoit3/docs/keywords.htm) Telegram.au3
$OFFSET = $msgData[0] + 1
$OFFSET = $msgData^ERROR
Error: Subscript used on non-accessible variable
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
Please do look into this and update the UDF accordingly. Thanks.