LinkOut

Telegram Bot UDF

34 posts in this topic

#21 ·  Posted

On 05/01/2017 at 11:49 PM, LinkOut said:

it's 100% safe and secure,

Curl may be, but Telegram itself is not. Using it for secure communications without two-factor authentication leaves a security hole you can drive a truck through, see for example here, here, here, and here.

Share this post


Link to post
Share on other sites



#22 ·  Posted

I created an issue at your repository :)

Quote

"AutoIT" used instead of "AutoIt"

The correct capitalisation is AutoIt (pronounced Aww - Toe - It). Not Auto - I.T 😜

 

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#23 ·  Posted

On 12/1/2017 at 8:18 AM, bambus1980 said:

its cool, but, what about using proxy server, ntlm proxy? if I use curl it will be: curl -s -k -U : --proxy-ntlm --proxy server:port https://google.com -o index.htm

how make that UDF working with proxy?

If you want to use proxy with cURL, download the older version of the UDF and add your commands to the $query that start curl with arguments.
 

On 12/1/2017 at 10:14 AM, RTFC said:

Curl may be, but Telegram itself is not. Using it for secure communications without two-factor authentication leaves a security hole you can drive a truck through, see for example here, here, here, and here.

I think that if you use THIS udf for secure communications... it's not the right thing.

On 12/1/2017 at 11:32 AM, TheDcoder said:

I created an issue at your repository :)

 

 
I saw! Thanks^_^

Share this post


Link to post
Share on other sites

#24 ·  Posted

Many thanks for your script, I am seeking for this for a long time other than python one.

I had a few issues and not sure is it should related to this UDF and ask here.

1. Proxy issue also, it can't detect my computer setting for the proxy set inside IE.

2. How to convert the non english text received as unicode code point to readable string e.g. \u5514\u7dca\u8981 ?

3. How to send emoji using sendmessage?

Share this post


Link to post
Share on other sites

#25 ·  Posted

On 16/2/2017 at 9:30 AM, mintea said:

Many thanks for your script, I am seeking for this for a long time other than python one.

I had a few issues and not sure is it should related to this UDF and ask here.

1. Proxy issue also, it can't detect my computer setting for the proxy set inside IE.

2. How to convert the non english text received as unicode code point to readable string e.g. \u5514\u7dca\u8981 ?

3. How to send emoji using sendmessage?

1. I don't really know how to use a proxy with the WinHttp udf that the script use. You can search for a different library that allow direct connection between a proxy, and use this to send http request to Telegram server;

2. \u5514\u7dca\u8981 <- this is the Unicode of an Emoji. You canconvert this to another encoding format but...

3. You can find ready-made UDFs that manage Emoji and can convert encoding to another and send them to Telegram. Or, better, SciTE (or Notepad++) support UTF-8 encoding and you can just copy emojis from telegram or emojipedia and paste directly into source code, and done!

 

Share this post


Link to post
Share on other sites

#26 ·  Posted

Thanks a lot for UDF. Someone else can give an example of inline_keyboard?

Share this post


Link to post
Share on other sites

#27 ·  Posted

On 4/3/2017 at 0:55 AM, sakamoto said:

Thanks a lot for UDF. Someone else can give an example of inline_keyboard?

Thank you for using it! To use inline_keyboard first you have to create an array of array of button (sound bad, I know) and then add this (encoded in json format) to the query. I'm working on it but only in php for the moment. If this can help you:

$keyboard = array("inline_keyboard" => array(array(array("text" => "ButtonText", "callback_data" => "CallbackText"),array("text" => "ButtonText2", "callback_data" => "CallbackText2"))));
$keyboard = json_encode($keyboard, true);

And after send it as:

http://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=12345678&text=test&reply_markup=$keyboard

 

Share this post


Link to post
Share on other sites

#28 ·  Posted (edited)

LinkOut, thanks for the answer.

I figured out the buttons, but get an error when receiving callback_data.

Other methods "url" "switch_inline_query" work out well.

#include "Telegram UDF.au3"
$ikeyb = '{"inline_keyboard":[[{"text":"Button 1","callback_data":"data 1"}]]}'
_InitBot("xxxIDxxx","xxxTOKENxxx")

While 1
    $msgData = _Polling()
    If $msgData <> '' Then ConsoleWrite($msgData[0]&'|'&$msgData[1]&'|'&$msgData[2]&'|'&$msgData[3]&@LF)
    Switch $msgData[3]
        Case '777'
            _SendMsg($msgData[2], 'Message', Default, $ikeyb)
    EndSwitch
WEnd
Telegram UDF.au3" (481)

$dataArray[2] = $tmpChatID[3]
$dataArray[2] = ^ ERROR

 

Edited by sakamoto

Share this post


Link to post
Share on other sites

#29 ·  Posted (edited)

My post above are no longer relevant.
I modified _JSONDecode function to return more variables:

     $msgData[4] = Callback query ID
     $msgData[5] = Callback data
     $msgData[6] = MessageID

And add new functions to respond to callback query:


     _answerCallbackQuery($ChatID, $Text, $Alert = True, $Cache_time = '5')
     _editMessageReplyMarkup($ChatID, $message_id, $reply_markup)
     _editMessageText($ChatID, $message_id, $Text, $reply_markup)

This for my bot is still enough.

Func _JSONDecode($JSONMsg)
   Local $firstSplit = StringSplit($JSONMsg,"update_id",1)
   Local $secondSplit = StringSplit($firstSplit[2], ",")
   Local $dataArray[7]
   For $i=1 to $secondSplit[0]
      Local $data = $secondSplit[$i]
      If StringLeft($data,2) = '":' Then $dataArray[0] = StringTrimLeft($data,2)
      If StringInStr($data,'username') Then
         $tmpUsername = StringSplit($data,':')
         $tmpUsername[2] = StringTrimLeft($tmpUsername[2],1)
         $tmpUsername[2] = StringTrimRight($tmpUsername[2],1)
         $dataArray[1] = $tmpUsername[2]
      EndIf
      If StringInStr($data,'"chat"') Then
         $tmpChatID = StringSplit($data,':')
         $dataArray[2] = $tmpChatID[3]
      EndIf
      If StringInStr($data,'text') Then
         $tmpText = StringSplit($data,':')
         If StringInStr($tmpText[2],'"}}]}') Then
            $tmpText[2] = StringTrimLeft($tmpText[2],1)
            $tmpText[2] = StringTrimRight($tmpText[2],5)
            $dataArray[3] = $tmpText[2]
         ElseIf StringInStr($tmpText[2],'"}}') Then
            $tmpText[2] = StringTrimLeft($tmpText[2],1)
            $tmpText[2] = StringTrimRight($tmpText[2],3)
            $dataArray[3] = $tmpText[2]
         ElseIf StringInStr($tmpText[2],'"}') Then
            $tmpText[2] = StringTrimLeft($tmpText[2],1)
            $tmpText[2] = StringTrimRight($tmpText[2],2)
            $dataArray[3] = $tmpText[2]
         ElseIf StringRight($tmpText[2],1) = '"' Then
            $tmpText[2] = StringTrimLeft($tmpText[2],1)
            $tmpText[2] = StringTrimRight($tmpText[2],1)
            $dataArray[3] = $tmpText[2]
         EndIf
      EndIf
      If StringInStr($data,'callback_query') Then
         $tmpCallBQ = StringSplit($data,':')
         $tmpCallBQ[3] = StringTrimLeft($tmpCallBQ[3],1)
         $tmpCallBQ[3] = StringTrimRight($tmpCallBQ[3],1)
         $dataArray[4] = $tmpCallBQ[3]
     EndIf
      If StringInStr($data,'data') Then
         $tmpCallBData = StringSplit($data,':')
         If StringInStr($tmpCallBData[2],'"}}]}') Then
            $tmpCallBData[2] = StringTrimLeft($tmpCallBData[2],1)
            $tmpCallBData[2] = StringTrimRight($tmpCallBData[2],5)
            $tmpCallBData[2] = $tmpCallBData[2]
            $dataArray[5] = $tmpCallBData[2]
         ElseIf StringInStr($tmpCallBData[2],'"}}') Then
            $tmpCallBData[2] = StringTrimLeft($tmpCallBData[2],1)
            $tmpCallBData[2] = StringTrimRight($tmpCallBData[2],3)
            $dataArray[5] = $tmpCallBData[2]
         ElseIf StringInStr($tmpCallBData[2],'"}') Then
            $tmpCallBData[2] = StringTrimLeft($tmpCallBData[2],1)
            $tmpCallBData[2] = StringTrimRight($tmpCallBData[2],2)
            $dataArray[5] = $tmpCallBData[2]
         ElseIf StringRight($tmpCallBData[2],1) = '"' Then
            $tmpCallBData[2] = StringTrimLeft($tmpCallBData[2],1)
            $tmpCallBData[2] = StringTrimRight($tmpCallBData[2],1)
            $dataArray[5] = $tmpCallBData[2]
        EndIf
     EndIf
    If StringInStr($data,'message_id') Then
         $tmpMsgID = StringSplit($data,':')
         $dataArray[6] = $tmpMsgID[3]
     EndIf
   Next
   If $dataArray[1] = '' Then
      For $i=1 to $secondSplit[0]
         If StringInStr($secondSplit[$i],'first_name') Then
            $tmpUsername = StringSplit($secondSplit[$i],':')
            $tmpUsername[2] = StringTrimLeft($tmpUsername[2],1)
            $tmpUsername[2] = StringTrimRight($tmpUsername[2],1)
            $dataArray[1] = $tmpUsername[2]
         EndIf
      Next
   EndIf
   Return $dataArray
EndFunc ;==> _JSONDecode



Func _answerCallbackQuery($ChatID, $Text, $Alert = True, $Cache_time = '5')
   Local $Query = $URL & "/answerCallbackQuery?callback_query_id=" & $ChatID &"&text=" & $Text & "&show_alert=" & $Alert & "&cache_time=" & $Cache_time
   Local $Response = HttpPost($Query)
   ;Return $Response
   Return True
EndFunc ;==> _answerCallbackQuery

Func _editMessageReplyMarkup($ChatID, $Message_id, $Reply_markup)
   Local $Query = $URL & "/editMessageReplyMarkup?chat_id=" & $ChatID  &"&message_id=" & $Message_id & "&reply_markup=" & $Reply_markup
   Local $Response = HttpPost($Query)
   ;Return $Response
   Return True
EndFunc ;==> _editMessageReplyMarkup

Func _editMessageText($ChatID, $Message_id, $Text, $Reply_markup)
   Local $Query = $URL & "/editMessageText?chat_id=" & $ChatID  &"&message_id=" & $Message_id & "&text=" & $Text & "&reply_markup=" & $Reply_markup
   Local $Response = HttpPost($Query)
   ;Return $Response
   Return True
EndFunc ;==> _editMessageText

 

Edited by sakamoto

Share this post


Link to post
Share on other sites

#30 ·  Posted (edited)

21 hours ago, sakamoto said:

<snip>

<snip>

 

Wow, awesome work. Thank you for share. I'm trying to find an easy way to split the message like json_decode function in PHP to make easier this process.

Edited by Melba23
Removed huge unecessary quote

Share this post


Link to post
Share on other sites

#32 ·  Posted

LinkOut,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

volond,

Welcome to the AutoIt forums. But as this is an English speaking forum, it would have helped more if you had translated the link.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#33 ·  Posted

can someone please help me where to find CHATID and BOTID ?

@BotFather only gives me token of the bot.

 

Thanks.

Share this post


Link to post
Share on other sites

#34 ·  Posted (edited)

CHATID is the id of the person the BOT receives/sends the messages to, so simply send an messages from your personal telegram account to the BOTID you have created and then  read that message with the BOT's account information. You will find the CHATID in the returned JSON information.

Jos 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

  • Similar Content

    • Gowrisankar
      By Gowrisankar
      Good day to the members of the forum.. 
      Is there any UDF that is available to automate Attachmate Extra Mainframe sessions?
      I am trying to automate mainframe processes. I couldn't get values from particular co-ordinates in mainframe or pass values to particular co-ordinates in mainframe.
      Please let me know if there is any UDF or any other kind of solution is available. 
      Thanks and regards,
      Gowrisankar R.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I would like to know if I can use the Excel UDF to manipulating a .csv file without having Office installed on the PC I'm going to work...
      I read somewhere that it could be done, but I'm here to ask and be sure of what I remember... 
      I'd like to post another question...
      How can I retrieve the handle of a windows from a PID of an .exe?
      I have my script that does a ShellExecute ( which returns the PID of the .exe ), and then, switching a parameter read from a .ini file, adapt the Window on the screen ( Maximize, Minimize, On Top )...
      I tried, but without having success with this:
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioniIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioniIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioniIni[2][1]) Case $aSezioniIni[2][1] = "MIN" WinSetState($hWnd, "", @SW_MINIMIZE) Case $aSezioniIni[2][1] = "MAX" WinSetState($hWnd, "", @SW_MAXIMIZE) Case $aSezioniIni[2][1] = "TOP" WinSetOnTop($hWnd, "", $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf It just set on top the .exe I'm launching...
      Thanks
    • TheSaint
      By TheSaint
      I had a need, and so I developed.
      Before I did that though, I did a quick search of the forum, and found a few things, but none seemed to suit what I really wanted ... though to be honest, I did not investigate them deeply or search extensively. In any case, I am not very good at modifying the code of others, nor do I enjoy doing so, so in the end I decided it was best to start from scratch ... re-inventing the wheel perhaps, but a wheel I feel a certain degree of comfort with. I also thought about Maps, but don't know enough.
      _IniString Functions (was Ini_InMem)
      Ini in memory
      Settings INI - Read/Write once to the disk
      INI File Processing Functions
      ... sure to be others.
      As with all my stuff, feel free to use (no guarantees) or modify ... just give me credit where due.
      I always go for the quick & simple approach, as those who know me here, are well aware, so without a doubt, my code could be improved - sped up, RegExp used, etc. So feel free to do that, and convert into a proper UDF, if you want, following best practices etc, as I am sure others will appreciate it.
      Recently, I have come upon a need to extract data from an approximately 50 Mb downloaded Index file, just extracting the few elements I need, and storing them in an INI file. It is quite a time consuming process, especially on my underpowered Netbook, which is where I am using the program I built. I have been considering ways to speed up things. Two good sounding methods, out of several possibles, have come to mind - 1) RAM Disk and 2) Virtual INI processing. That last being a better option, when sharing code (program) with others.
      Another method, which I am currently using, that did give me some measurable benefit, was to download the almost 50 Mb Index file in Stages (i.e. 30 x 1.4 Mb roughly), extracting data from each in turn. I have also considered extracting to 10 (or 11) separate INI files, rather than the single large INI file (4~5 Mb), as things noticeably slow up as the INI file increases in size ... obviously due to writing time.
      I can't really speed up the extraction process, but that last method may speed up the writing stage.  However, it would require significant program changes, and perhaps not gain me much benefit. To complicate things, there are too many Section names (Index ID's) for the IniReadSectionNames command, so I have had to split them off into their own (read/write) line-by-line index file, and create code to deal with duplicates. When read, Index ID's and Titles populate a Listbox control in a user GUI.
      So at this point in time, it seems best to use the Virtual INI approach to gain a significant reduction in time taken. For my own specific use, with my slow Netbook, I may also use a RAM Disk.
      Due to the aforementioned INI issues, and lack of available specific data, probably because it is always  program concentric, I have created an ASCII Checker program, which I guess you can say, is AutoIt  concentric. Because others may also find it handy, I am providing it here. NOTE - As yet, I am only aware that Escape characters exist, but have not investigated or catered for them in any way.
      ASCII Checker.zip

      The Virtual_INI_UDF is still a work in progress, though I have done most of the functions now, with the working but incomplete _Ini_Test function, still requiring changes etc from the information gleaned by the ASCII Checker program.
      Here's something to play with meanwhile.
      Updated files (24th February 2017)
      Virtual_INI_UDF.au3  NEW
      Example.au3 (23rd February 2017)
      All pretty basic, but managed to load my 4 Mb INI file (seemingly ok, but took a few seconds) ... though I have only worked with much smaller testing ones so far.
      P.S. While I have done a fair amount of testing, it has been pretty basic, and mostly limited to the examples provided. Testing has definitely not been extensive.
       
    • XOblivion
      By XOblivion
      im some what new to autoit and need help figuring out best way to make a simple clicker for few idle games i play(taptitdue, sakura clicker, elndless frontier etc.) ive played around with autoit recorder to make simple copy mouse clicks. but now i want to make a script that allows me to select multiple functions before starting the script for game ex: click section A or click section A + B to run At set intervals if that makes sense . i dont need scripts made by other just info on what things i should use to make it my self.
       
      need to be able to select between games and be able to select multiple functions to run inconjuntion or independent for each game. thank you in advance
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management

      DISCLAIMER:
      This UDF is still in the development phase. All code works and should be generally bug free, however function names and parameters are subject to change.
       
      Notes:
      Fixes _WindowGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.