Jump to content

Recommended Posts

  • 2 months later...
On 3/29/2022 at 9:12 PM, marko001 said:

I get same error message too, any suggestion?

 

Hi! I've found answer about this bug. It seems that bot could not read messages. try to fix this way:

1) go to https://api.telegram.org/bot<BOT_TOKEN>/getupdates

2) in the list of messages in JSON get the last "Update_id" field

3) go to https://api.telegram.org/bot<BOT_TOKEN>/getupdates?offset="Update_id"

4) try to launch your bot, must be fine

Link to comment
Share on other sites

  • 2 weeks later...

hi  how  is possible  send  message  in multiline ???

i try in this mode  but not work

$MsgID = _SendMsg($ChatID, "Hi! I'm ste  ciao :) "&$aDataArray[2]& @CRLF &"ciao mare")
    ConsoleWrite($MsgID & @CRLF)
    
    or
        $MsgID = _SendMsg($ChatID, "Hi! I'm ste  ciao :) "&$aDataArray[2] \n ciao mare")
    ConsoleWrite($MsgID & @CRLF)

 

Link to comment
Share on other sites

Check this post: 

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 1 month later...
12 minutes ago, Jos said:

Why not post your proposal here so others can benefit too?
 

Attached changes in zipfile to my previous post. Any alterations or improvements are welcome as well.
On my Synology HTTP proxy, everything works.
I have been trying with MITM proxy (Free https proxy server) for the HTTPS proxy variant, but that needs some more investigation to get that working.

Edited by lbsl
Link to comment
Share on other sites

  • 1 month later...

Hi  sorry if i disturb i try to use the  example  of  this udf  but  return me this error

Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit).
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.
Insert this data in the source code.
(1104) : ==> The requested action with this object has failed.:
$oHTTP.Send()
$oHTTP^ ERROR

but  i ma sure  100%  i use a correct CHat id  And  token

the  code  but is  a example code

#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 = '-10000000000' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = "xxxxxxxxxxxxxxxxxxx" ;Token here

If(($ChatID = '') or ($Token = '')) Then
    ConsoleWrite("Warning! ChatID or Token not specified!")
    Exit -1
EndIf

ConsoleWrite("! Initializing bot... " & _InitBot($Token) & @CRLF & @CRLF)

ConsoleWrite("Who am I? ")
Local $myData = _GetMe()
ConsoleWrite("Oh, yeah, my name is " & $myData[2] & ", you can find me at @" & $myData[1] & ". For developers, my Telegram ID is " & $myData[0] & @CRLF)

ConsoleWrite("Let's do some test:" & @CRLF)
ConsoleWrite(@TAB & "Sending a simple text message. The function _SendMsg return the Message ID: ")
$MsgID = _SendMsg($ChatID,"Hi! I'm " & $myData[2] & " :)")
ConsoleWrite($MsgID & @CRLF)
;ConsoleWrite(@TAB & "Now I'll forward the same message to you, with the message id saved before: " & _ForwardMsg($ChatID,$ChatID,$MsgID) & @CRLF)
ConsoleWrite(@TAB & "Awesome. Use the other _Send functions to send photos, videos, documents. Each function return the FileID assigned by Telegram." & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,'media/image.png',"This is a photo.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending video: " & _SendVideo($ChatID,'media/video.mp4',"This is a video.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending audio: " & _SendAudio($ChatID,'media/audio.mp3',"This is an audio.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending documents: " & _SendDocument($ChatID,'media/text.txt',"This is a document.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending voice: " & _SendVoice($ChatID,'media/voice.ogg',"This is a voice.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending sticker: " & _SendSticker($ChatID,'media/sticker.webp') & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending video note: " & _SendVideoNote($ChatID,'media/video.mp4') & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending location: " & _SendLocation($ChatID,"74.808889","-42.275391") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending contact: " & _SendContact($ChatID,"0123456789","John","Doe") & @CRLF & @CRLF)

ConsoleWrite("You can send a 'Chat Action', that mean the user see 'Bot is typing...' or 'Bot is sending a photo...'." & @CRLF & @CRLF)
_SendChatAction($ChatID,'typing')

ConsoleWrite("To use a custom keyboard, there is an useful function that contruct and encode the keyboard itself." & @CRLF & _
             "You have to create an array and insert the text of your buttons. To line break, leave a position empty. " & @CRLF & _
             "Example, try to pass this array $keyboard[4] = ['TopLeft','TopRight','','SecondRow'] to the _CreateKeyboard function, then send the message." & @CRLF & @CRLF)

Local $keyboard[4] = ['TopLeft','TopRight','','SecondRow']
Local $markup = _CreateKeyboard($keyboard)
ConsoleWrite("In encoded format, the $keyboard look like " & $markup & @CRLF & _
             "I'll send this keyboard to you as this: _SendMsg($ChatID,'Hey! Choose one:',Default,$markup)" & @CRLF)
_SendMsg($ChatID,'Hey! Choose one:',Default,$markup)
ConsoleWrite("_CreateKeyboard function accept two other boolean args, resize and one time keyboard, both false by default." & @CRLF & @CRLF)

ConsoleWrite("This is all folks! For all the other methods read the Telegram Documentation and the Telegram.au3 file, it's commented. You can find some examples in the example folder." & @CRLF)
ConsoleWrite("Don't forget to ì star this repo on GitHub, this mean a lot for me.")

thanks

Link to comment
Share on other sites

22 hours ago, aldrovan said:

Hi  sorry if i disturb i try to use the  example  of  this udf  but  return me this error

Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit).
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.
Insert this data in the source code.
(1104) : ==> The requested action with this object has failed.:
$oHTTP.Send()
$oHTTP^ ERROR

but  i ma sure  100%  i use a correct CHat id  And  token

the  code  but is  a example code

#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 = '-10000000000' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = "xxxxxxxxxxxxxxxxxxx" ;Token here

If(($ChatID = '') or ($Token = '')) Then
    ConsoleWrite("Warning! ChatID or Token not specified!")
    Exit -1
EndIf

ConsoleWrite("! Initializing bot... " & _InitBot($Token) & @CRLF & @CRLF)

ConsoleWrite("Who am I? ")
Local $myData = _GetMe()
ConsoleWrite("Oh, yeah, my name is " & $myData[2] & ", you can find me at @" & $myData[1] & ". For developers, my Telegram ID is " & $myData[0] & @CRLF)

ConsoleWrite("Let's do some test:" & @CRLF)
ConsoleWrite(@TAB & "Sending a simple text message. The function _SendMsg return the Message ID: ")
$MsgID = _SendMsg($ChatID,"Hi! I'm " & $myData[2] & " :)")
ConsoleWrite($MsgID & @CRLF)
;ConsoleWrite(@TAB & "Now I'll forward the same message to you, with the message id saved before: " & _ForwardMsg($ChatID,$ChatID,$MsgID) & @CRLF)
ConsoleWrite(@TAB & "Awesome. Use the other _Send functions to send photos, videos, documents. Each function return the FileID assigned by Telegram." & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,'media/image.png',"This is a photo.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending video: " & _SendVideo($ChatID,'media/video.mp4',"This is a video.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending audio: " & _SendAudio($ChatID,'media/audio.mp3',"This is an audio.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending documents: " & _SendDocument($ChatID,'media/text.txt',"This is a document.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending voice: " & _SendVoice($ChatID,'media/voice.ogg',"This is a voice.") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending sticker: " & _SendSticker($ChatID,'media/sticker.webp') & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending video note: " & _SendVideoNote($ChatID,'media/video.mp4') & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending location: " & _SendLocation($ChatID,"74.808889","-42.275391") & @CRLF)
ConsoleWrite("!" & @TAB & @TAB & "Sending contact: " & _SendContact($ChatID,"0123456789","John","Doe") & @CRLF & @CRLF)

ConsoleWrite("You can send a 'Chat Action', that mean the user see 'Bot is typing...' or 'Bot is sending a photo...'." & @CRLF & @CRLF)
_SendChatAction($ChatID,'typing')

ConsoleWrite("To use a custom keyboard, there is an useful function that contruct and encode the keyboard itself." & @CRLF & _
             "You have to create an array and insert the text of your buttons. To line break, leave a position empty. " & @CRLF & _
             "Example, try to pass this array $keyboard[4] = ['TopLeft','TopRight','','SecondRow'] to the _CreateKeyboard function, then send the message." & @CRLF & @CRLF)

Local $keyboard[4] = ['TopLeft','TopRight','','SecondRow']
Local $markup = _CreateKeyboard($keyboard)
ConsoleWrite("In encoded format, the $keyboard look like " & $markup & @CRLF & _
             "I'll send this keyboard to you as this: _SendMsg($ChatID,'Hey! Choose one:',Default,$markup)" & @CRLF)
_SendMsg($ChatID,'Hey! Choose one:',Default,$markup)
ConsoleWrite("_CreateKeyboard function accept two other boolean args, resize and one time keyboard, both false by default." & @CRLF & @CRLF)

ConsoleWrite("This is all folks! For all the other methods read the Telegram Documentation and the Telegram.au3 file, it's commented. You can find some examples in the example folder." & @CRLF)
ConsoleWrite("Don't forget to ì star this repo on GitHub, this mean a lot for me.")

thanks

There is quite enough not fine with this UDF, part of it is not the fault of the original developer and my additions may not be perfect either.

There are in total 4 issues with this UDF that keeps it from generally usable:
1)I have been transcoding parts of this UDF to work with Curl instead, this is just for the fact that the WinHTTP COM library has been neglected by Microsoft for older versions of Windows and i don't have the elevated user rights to patch the issue -> Using Curl you are not depending upon the Windows environment for getting secure ssl communication to work. If you cannot use secured connections, it might be your winodws WinHTTP needs to be patched with a KB update supporting TLS 1.1 and higher, but that depends on your windows version (windows 7 or lower)
The Curl routines is too much to post as snippets into this post, when i am done with it, i may add the updated UDF with all the below mentioned options.

The next alteration snippets will at least render this original UDF more effective for serious projects

2)The second issue is the fact that the polling function does not allow you to build a decent GUI around your project. You can circumvent that by implementing your own sleep function that polls for the GUImsg response queue and network queue and whatever message services you need to monitor.

;__UserPoll is not a strictly required function, this is to prevent Au3check from nagging about it, add it near your #includes
#ignorefunc __UserPoll


Func __PauseTimer($msecs)
    Local $WaiTime = TimerInit()
    While 1
        If IsFunc(__UserPoll) Then __UserPoll()
        If TimerDiff($WaiTime) >= $msecs Then
            Return
        EndIf
    WEnd
EndFunc   ;==>__PauseTimer

__Pausetimer() calling is done from the __polling() function shown in issue 4 (It replaces the sleep(1000) line)

An example of what __UserPoll can be...
 

Func __UserPoll() ;Process functions during msg polling
    ;ConsoleWrite(@HOUR & @MIN & @SEC & @MSEC & ":Checking poll" & @CRLF)
    If TrayGetMsg() == $TrayExit Then Exit
    If $ExitTimer > 0 And TimerDiff($ExitTimer) > 5000 Then
        Exit
    EndIf

    __CheckMachineStates()
EndFunc   ;==>__UserPoll


3)The third issue is the fact that Telegram UDF utilizes the Json UDF (and a rather old version of it), not necessarily the Json UDF is the issue, but the Json UDF utilizes the Binary UDF that uses the OnAutoItExitRegister function taking away the ability to reuse it in your project. Yes you can use it, but your program will crash on exit because the binarycall udf cannot clear its memory. To get around this, you have to take care the __BinaryCall_DoRelease() function is called in your exit function, or build a Telegram_Close() function that calls this one (best practice option) that you call from within yours.

Func Telegram_Close()
    __BinaryCall_DoRelease()
EndFunc
Func _BinaryCall_ReleaseOnExit($Ptr)
    ;OnAutoItExitRegister('__BinaryCall_DoRelease') ; Remove or quote out this function in BinaryCall.au3!
    __BinaryCall_ReleaseOnExit_Handle($Ptr)
EndFunc



4) The last issue is also related to Binarycall UDF, specially the routine to release the reserved handles __BinaryCall_DoRelease() as it is only called on close/exit in the current state.  When the telegram polling routine keeps looping, the pointers are being kept generated causing your project to become a huge memory hogger, so this is a big fat leak issue that has to be fixed as well. The Telegram UDF has to call the __BinaryCall_DoRelease() more often from within it's polling function to prevent your application reserved memory from getting ' obese' 

#cs ===============================================================================
    Function Name..:        _Polling
    Description....:     Wait for incoming messages
    Parameter(s)...:     None
    Return Value(s):        Return an array with information about the messages
#ce ===============================================================================
Func _Polling()
    While 1
        __PauseTimer(1000) ;Prevent CPU Overloading
        If $BinaryCleanTimer > 0 And TimerDiff($BinaryCleanTimer) > 60000 Then ; Clean Json buffers every 60 seconds to prevent memory clogging!
            $BinaryCleanTimer = TimerInit()
            __BinaryCall_DoRelease()
        Else
            $BinaryCleanTimer = TimerInit()
        EndIf

        $newUpdates = _GetUpdates()
        If Not StringInStr($newUpdates, 'update_id') Then ContinueLoop
        $msgData = __MsgDecode($newUpdates)
        $OFFSET = $msgData[0] + 1

        Return $msgData
    WEnd
EndFunc   ;==>_Polling

 

Edited by lbsl
Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

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

Edited by noellarkin
clarity
Link to comment
Share on other sites

On 6/22/2022 at 8:35 PM, krashsa said:

Hi! I've found answer about this bug. It seems that bot could not read messages. try to fix this way:

1) go to https://api.telegram.org/bot<BOT_TOKEN>/getupdates

2) in the list of messages in JSON get the last "Update_id" field

3) go to https://api.telegram.org/bot<BOT_TOKEN>/getupdates?offset="Update_id"

4) try to launch your bot, must be fine

Tried this, getting the same error

Link to comment
Share on other sites

  • Developers
7 minutes ago, noellarkin said:

Tried this, getting the same error

Not really much to go on is there?

So are the steps 1-3 working for you and only step isn't?

Also: Why are you assuming the array will always be filled?

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

Just now, Jos said:

Not really much to go on is there?

So are the steps 1-3 working for you and only step isn't?

I've already specified the error in this post:

16 minutes ago, 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

I've included the code used as well as the error message. Thanks for looking into it.

Link to comment
Share on other sites

8 minutes ago, Jos said:

Also: Why are you assuming the array will always be filled?

not sure what you mean by this, I got these errors from the example script provided, I haven't made any changes other than setting the value for token.
I've sent a few messages to the Bot using the Telegram app so there should be enough JSON data for it to read and echo back.

Link to comment
Share on other sites

  • Developers

I have just tested your code and added _arrayDisplay() after the polling and for me there is NO $msgData[5], only 0-4!

$msgData = _Polling()
    _ArrayDisplay($msgData)

So its seems your code is wrong?

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

3 minutes ago, Jos said:

I have just tested your code and added _arrayDisplay() after the polling and for me there is NO $msgData[5], only 0-4!

$msgData = _Polling()
    _ArrayDisplay($msgData)

So its seems your code is wrong?

It wasn't my code, it's one of the example .au3s (EchoBot.au3), part of the UDF linked to in the first post. I made no changes other than inserting the value of Token.
I assumed the example code would work since this UDF is in the AutoIt wiki. Here's where I got it from:
https://github.com/xLinkOut/telegram-udf-autoit
https://github.com/xLinkOut/telegram-udf-autoit/blob/master/example/EchoBot.au3

Thanks for clarifying. I've commented out all the lines in the While Loop except the Polling and I added an ArrayDisplay as well:

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

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

$Token = "dfgdfgdfgdg" ;Token here
_InitBot($Token)

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

Func _Exit()
    Exit 0
EndFunc


However, I'm still getting the error:
Line 794 in Telegram.au3

$OFFSET = $msgData[0] + 1

$OFFSET = $msgData^ERROR

Error: Subscript used on non-accessible variable

Link to comment
Share on other sites

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...