Hi Frosti, nice to see some interest in the subject.
Frosti wrote:There are many critics about this app, but call me a social app that has such independence from governments and intelligence agencies. You also have to know something about the two financiers. They are one of the few we can trust, I think.
While I like the Telegram app and its botting capabilities very much, that sounds like a bold statement. Even, if the Durovs seem like honest guys, there is no guarantee that they really are. And the FSB - and probably not only them - are putting heavy pressure on them to hand them the keys. Even if they do not, there is no guarantee that some secret service or hacker won't find a weak spot/bug to exploit already tomorrow. That is the same for every messenger app - all I am saying is: This is just an app - and it is not saver or more trustable than any other messenger app. And with things like patient data I still would be
extremely careful.
That said, I use my telegram bots on a daily basis - still for private use cases, but also thinking of using them professionally - but the handling of customer data is surely a difficult subject that stopped me, so far. I might rather switch to a webserver/php approach, If I want to implement some customer/commercial-use-bot.
Frosti wrote:I think the Telegram app is the next big thing that changes the internet. And we do not have a wrapper or a half or full bot in this forum yet. I tried it for myself. But my attempt makes me dissatisfied. My tries with Coco's Library have failed. I then developed a solution for myself through RegEx. But I also find these unsatisfactory.
I have only glanced over your bot so far (will test it later), but what are the reasons of your dissatifaction? If you could expand a bit on that, people might have an easier time to recommend improvements.
I am surprised that Coco's library didn't work for you. I use it a lot - for a whole range of APIs, not only telegram. While it surely could have bugs or weaknesses, it works well for me with Telegram and my other use cases. So, how did it fail? Didn't it work at all? What did you try?
Before programming my own parser, I would have surely tried a lot
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
But there is at least one pitfall, that you have to be aware of, if I remember correctly. The class JSON makes the the term
json a reference (?) to super-global object. That means, if you are using some other variable/object called
json in your script, it will most probably mess things up. (That is a general thing with classes in AHK - I remember how I was chasing for the reason of some mystery bugs, when I used another class, a while back. I nearly lost my mind over it
![Shh :shh:](./images/smilies/icon_shh.gif)
).
Frosti wrote:Please gregster can you tell me how your bot works. I'm telling it all he needs (Token and ChatID) but there is no response from your script. And then I have problems to stop your script. Neither the escape key nor a right-click on the tray icon work.
Well, that sounds odd
![Shocked :shock:](./images/smilies/icon_eek.gif)
. Like you can see, it is a rather short script that doesn't do very much. I just re-downloaded it, added my credentials and the json lib to the script directory, and it worked. labrint never reported back after I posted it, but if I didn't miss something hardcoded in the script that would mess it up on another machine, it
should work.
At least, it shouldn't freeze - that is something I rarely experienced at all with AHK scripts in 12+ years.
I don't think the reason could be the included JSON class by Coco. But you could remove the
#include-line for testing. The script should still start and show the message "Keyboard added" and a custom keyboard in the bot/chat you specified. (Of course, without a JSON parser, it wouldn't be able to react to user messages after that)
If I would have to guess, the most likely reason seems to be the
URLDownloadToVar function, although I never had problems with the
WinHTTP 5.1 COM interface, so far - I use it also with other APIs. Perhaps it gets stuck somehow... does this function work in other scripts for you - or not at all? I saw that you use some other function (with another technique/interface) - here you can see a comparison of the different techniques we use:
WinHTTP versus
WinINet https://msdn.microsoft.com/en-us/librar ... s.85).aspx . Perhaps there is some firewall setting or security program on your system that prevents the use of the
WinHTTP 5.1 COM interface - or perhaps something is broken. One would have to investigate some more, if this function would be the reason of your problems
That said, I replaced
URLDownloadToVar() from my script with the
DownloadToString() function you are using - and as I expected, my script still worked. (For testing, I only replaced the contents of my function with the contents of the other - so that I didn't have to change any function calls in other parts of the script.)
So, if you are willing to test a little, I would be interested in the results. While I personally use my Class-based Telegram wrapper (still looking like a trainwreck, incomplete and with lazy error handling; and therefore not posted yet), I also rely there on the
URLDownloadToVar function I used above. If it could cause problems on other systems, I might investigate it further and/or replace it with a more robust function.
Btw, which AHK and windows versions are you using? I use AHK 64bit (ver 1.1.28) on Win 10 64bit - but when I wrote the script above, I was still using Win 7 64bit.
One other thing that caught my eye when glancing over your script, was the usage of the global variable
nooption in two functions. I didn't understand what you trying to do there - but perhaps you are using them in other script parts that you didn't post? So far, it just looks like an empty variable. At some point you are then doing this:
Code: Select all
straw:=DownloadToString(url, "utf-8")
if straw = nooption
return obj:="no_message"
That means, you are comparing the contents of the variable
straw with the
literal string "nooption" - and not with the (not existing !?) contents of the variable
nooption (because you are using traditional if-syntax without parentheses here: Compare
If ). Whatever these contents might be...
Perhaps you wanted to use
If-expression syntax instead to see if the response is empty?? But even if there are no messages, I don't think
straw would be empty - Telegram still returns
{"ok":true,"result":[]}, when there are no new updates.
straw could be empty (or 0), though, if the download function fails for some reason.
But anyway, that's all a minor thing (and perhaps the remains of something or something not fully implemented yet) and I didn't really look very closely so far, so I might be wrong with my observations. Just wanted to leave a note about it.
Happy botting!