Jump to content

Recommended Posts

On ‎06‎.‎01‎.‎2017 at 1:10 PM, Jos said:

I took one of the examples posted by trancexx and modified it to the below alternative UDF for SendPhoto:

#include <WinHttp.au3>

;~ ConsoleWrite("Test _SendMsg      -> "  & @TAB & _SendMsg($ChatID,"Test _SendMsg") & @CRLF)
;~ ConsoleWrite("Test _SendPhoto    -> " & @TAB & _SendPhoto($ChatID, "d:\temp\image.jpg", "Test _SendPhoto") & @CRLF)
ConsoleWrite("Test _SendPhoto    -> " & @TAB & _SendPhotoN($ChatID, "d:\temp\image.jpg", "Test _SendPhoto") & @CRLF)


; @SEND MEDIA FUNCTION using WINHTTP ================================================================================
Func _SendPhotoN($ChatID, $Path, $Caption = "")
    Local $Query = $URL & '/sendPhoto'
    $sForm = _
            '<form action="' & $Query & '" method="post" enctype="multipart/form-data">' & _
            ' <input type="text" name="chat_id"/>' & _
            ' <input type="file" name="photo"/>' & _
            ' <input type="text" name="caption"/>' & _
            '</form>'

    ; Initialize and get session handle
    $hOpen = _WinHttpOpen()
    $hConnect = $sForm ; will pass form as string so this is for coding correctness because $hConnect goes in byref
    ; Register callback function
    _WinHttpSimpleFormFill_SetUploadCallback(UploadCallback)
    ; Fill form
    $sHTML = _WinHttpSimpleFormFill($hConnect, $hOpen, _
            Default, _
            "name:chat_id", $ChatID, _
            "name:photo", $Path, _
            "name:caption", $Caption)
    ; Collect error number
    $iErr = @error
    ; Unregister callback function
    _WinHttpSimpleFormFill_SetUploadCallback(0)
    ; Kill progress bar window
    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    If $iErr Then
        MsgBox(4096, "Error", "Error number = " & $iErr)
        ConsoleWrite("! error:" & $iErr & @CRLF & $sHTML & @CRLF)
    Else
        ConsoleWrite($sHTML & @CRLF)
    EndIf
    Return $iErr

EndFunc   ;==>_SendPhotoN

This is working nicely for me :)

Jos

Hi jos thank you for your modifications for this udf but i'm still having the problem  when I try to send pictures or files ... but now with your udf I've an error 4..do you have a idea?? thank you for your help

mas

Link to comment
Share on other sites

1 hour ago, maskat said:

Hi jos thank you for your modifications for this udf but i'm still having the problem  when I try to send pictures or files ... but now with your udf I've an error 4..do you have a idea?? thank you for your help

mas

I've found the problem it came from our proxy... I tried your script with a conneciotn without proxy it' works perfectly thank you

Link to comment
Share on other sites

  • 9 months later...

I downloaded telegram UDF files from github.  I ran the sample code and most telegram functions failed.

Only the "send message" working well , the others such as send audio/image/video.... all failed.

I don't know what's wrong. Could some give me suggestion?

note: I used autoit v3.3.14.5

Link to comment
Share on other sites

  • 1 month later...
  • Developers

@karson_chan, you have to do better than that for anybody to be able to help you!
If it works on one PC, it should also work on the other given the files are on the exact same place.
So what about you show what you are doing by sharing the script etc?

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

@Jos

Actually all 5 pc is in same setting using same WiFi ssid. Firewall is off. Running in windows 10 64 bit. Using Autoit v3.3.14.5. 

Is there need to some setting i forgot?  i feel strange too. why only one pc work for me. It is just a simply script to test.

here are the script i am tesing: 

 

 

#include "../Telegram.au3"
$Token = '1111111:aaaaaaaaaaaaaaaaaaaavsog9RO4' ;owen2
$ChatID = '412777023' ;owen2

_InitBot($Token)

_SendPhoto($ChatID,'image.png',"This is a photo5.")
 

Edited by Jos
Link to comment
Share on other sites

  • Developers

I removed part of the token assuming you do not want to share that and have others using your bot! 
Are you getting any errors?
are you sure the file image.png is available in the default directory?

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

  • Developers

Screen captures do not help much, post the code please and just remove and personal stuff, so we can check.

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

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

When adding my bot to any channel - cant recieve any messages :(( 

log gives like this:

MSG#-1001195506482# - testbot: 
MSG#-1001195506482# - testbot: 
MSG#-1001195506482# - testbot: 
MSG#-1001195506482# - testbot: 
MSG#477888592# - Johnnie: test
MSG#477888592# - Johnnie: -301864711Хьюстон
MSG#477888592# - Johnnie: -301864711Хьюстон
MSG#271673891# - Denis: -301864711Хьюстон
MSG#271673891# - Denis: -301864711Хьюстон

 

Bot source look like this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Cryply.ico
#AutoIt3Wrapper_UseUpx=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "../Telegram.au3"
#include <Inet.au3>
#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>

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

$Token = '558290450:AAFEAM2pfNr7j0IFME-nJTBfCNeiuNNaAmE' ;Insert here your token
_InitBot($Token)


;-------------------------------------- %0A
Global $price = ""
Global $status = ""
Global $lowhigh = ""
Global $altprice = ""
;-------------------------------------- %0A


While 1
    $msgData = _Polling()
   ;;;;; ConsoleWrite("Incoming message from " & $msgData[3] & ": " & $msgData[5] & @CRLF)
   ;TrayTip($msgData[3]," user: " & $msgData[5],0)
    ;_SendMsg($msgData[2],$msgData[5]) <<<< https://youtu.be/30g356XW-nQ

    FileWrite(@ScriptDir&"\Cryply.log","MSG#"& $msgData[2] &"# - " & $msgData[4] & ": " & $msgData[5] & $msgData[6] & $msgData[7] & @CRLF)

if StringInStr($msgData[5],"!test" ) or StringInStr($msgData[5],"!тест") Then ;--------------------------------------
_SendMsg($msgData[2],"Works fine...")
endif

if StringInStr($msgData[5],"!admin") or StringInStr($msgData[5],"!author") or StringInStr($msgData[5],"!about") or StringInStr($msgData[5],"!автор") or StringInStr($msgData[5],"!админ") Then ;--------------------------------------
_SendMsg($msgData[2],"Неофициальный Крипли Бот v1.2 %0AАвтор Johnnie Walker %0AЕ-мейл: xbitnik@gmail.com")
endif

if StringInStr($msgData[5],"!mining") or StringInStr($msgData[5],"!майнинг") Then ;--------------------------------------
_SendMsg($msgData[2],"Обучающее видео по майнингу для новичков:%0A https://youtu.be/30g356XW-nQ")
endif

if StringInStr($msgData[5],"!moon") or StringInStr($msgData[5],"!tothemoon") or StringInStr($msgData[5],"/moon") or StringInStr($msgData[5],"/tothemoon") or StringInStr($msgData[5],"/themoon") Then ;--------------------------------------
_SendMsg($msgData[2],"If you want CRYPLY to the moon, start doing something. Anyone can help and every donat is important to us :) И Я, конечно, ни на что не намекаю... ")
endif

if StringInStr($msgData[5],"!links") or StringInStr($msgData[5],"!gettingstarted") or StringInStr($msgData[5],"!ссылки") or StringInStr($msgData[5],"!urls") Then ;--------------------------------------
_SendMsg($msgData[2],"" & _
"Сайт: https://cryply.io"& _
"%0AФорум: https://bitcointalk.org/index.php?topic=2634468.0;all"& _
"%0AОбменник: https://crex24.com/ru/exchange/CRP-BTC"& _
"%0AСтаты: https://www.coingecko.com/en/price_charts/cryply/usd"& _
"%0A%0AКошельки: https://goo.gl/gfx5Xv"& _
"%0AМайнеры: https://goo.gl/rb2zRb"& _
"%0AПулы: https://cryply.luckypool.org  и  https://p2pool.work%0A%0A")

endif


if StringInStr($msgData[5],"!info" ) or StringInStr($msgData[5],"!инфо") or StringInStr($msgData[5],"/start") Then ;-------------------------------------- ;"%0A!stats / !статы - полезная статистика манетки"& _
_SendMsg($msgData[2],"Список доступнык комманд: " & _
"%0A!info / !инфо - данная справка"& _
"%0A!links / !ccылки - ссылки на полезные ресурсы"& _
"%0A!price / !цена - текущая цена манетки"& _
"%0A!mining / !майнинг - майнинг видео для новичков"& _
"%0A!author / !автор - контактные данные автора")
endif


if StringInStr($msgData[5],"!time") or StringInStr($msgData[5],"!время") Then ;--------------------------------------
_SendMsg($msgData[2],"The time is: "&@HOUR&":"&@MIN&":"&@SEC)
endif


if StringInStr($msgData[5],"!price") or StringInStr($msgData[5],"!цена") Then ;--------------------------------------

$Text = _INetGetSource('https://coinlib.io/coin/CRP/Cryply',true)

$source = _StringBetween($Text, "$&nbsp;"," </span>")
If Not @error Then
    $price = "$ "&$source[0]
Else
$price = "?"
endif

$source = _StringBetween($Text, 'id="coin-price-delta">','</span>')
If Not @error Then
    $status = StringReplace($source[0],@LF,"")
Else
$status = "?"
endif

$source = _StringBetween($Text, 'coin-high-low">',' </div>')
If Not @error Then
    $lowhigh = StringReplace(StringReplace($source[0],"&nbsp;"," "),@LF,"")
Else
$lowhigh = "?"
endif

$source = _StringBetween($Text, 'price text-left pl-2">BTC','</span>')
If Not @error Then
    $altprice = StringReplace($source[0],@LF,"")
Else
$altprice = "?"
endif

;MsgBox(0,"Price",$price)
;MsgBox(0,"Status",$status)
;MsgBox(0,"LowHigh",$lowhigh)
;MsgBox(0,"ALtprice","BTC "&$altprice)
_SendMsg($msgData[2], "" _
&"Цена крипли в USD: "&StringStripWS($price,8) _
&"%0AЦена крипли в BTC: "&StringStripWS($altprice,8) _
&"%0AУровни за сутки: "&StringStripWS($lowhigh,8)&@CRLF _
&"%0AРейтинг: "&StringStripWS($status,8) _
&"%0AЗа 1000 CRP вы получите: "&StringStripWS(StringReplace($price,"$ ",""),8)*1000&" $")

;_SendMsg($msgData[2],"Cryply rate: "&$status)
;_SendMsg($msgData[2]," - - - - - - - - - - - ")
;_SendMsg($msgData[2],"10 Cryply = "&StringReplace($price,"$ ","")*10)
;_SendMsg($msgData[2],"50 Cryply = "&StringReplace($price,"$ ","")*50)
;_SendMsg($msgData[2],"100 Cryply = "&StringReplace($price,"$ ","")*100)
;_SendMsg($msgData[2],"1000 Cryply = "&StringReplace($price,"$ ","")*1000)
;_SendMsg($msgData[2],"1500 Cryply = "&StringReplace($price,"$ ","")*1500)
;_SendMsg($msgData[2],"2000 Cryply = "&StringReplace($price,"$ ","")*2000)
;_SendMsg($msgData[2],"5000 Cryply = "&StringReplace($price,"$ ","")*5000)
;_SendMsg($msgData[2],"10000 Cryply = "&StringReplace($price,"$ ","")*10000)
;_SendMsg($msgData[2]," - - - - - - - - - - - ")
;_SendMsg($msgData[2],"Stats based on coinlib.io/coin/CRP/Cryply")
endif





;--------------------------------------------------------------------------

WEnd

Func _Exit()
    Exit 0
EndFunc

 

 

Please HELP !

Edited by Enforcer
[RU] Zone
Link to comment
Share on other sites

  • 3 months later...

Probably you already solved the problem, anyway... you must change the privacy on the botFather, like explained in this quote from stackoverflow:

Quote

Sequence within a BotFather chat:

You: /setprivacy

BotFather: Choose a bot to change group messages settings.

You: @your_name_bot

BotFather: 'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.

'Disable' - your bot will receive all messages that people send to groups.

Current status is: ENABLED

You: Disable

BotFather: Success! The new status is: DISABLED. /help

 

Link to comment
Share on other sites

  • 2 weeks later...

I was trying to edit a previously sent message with a Photo with SendPhoto(), with a new photo with this Func:

Func _editMessageMedia($ChatID, $Message_id, $Path, $Reply_markup = Default )
    Local $Query = $URL & '/editMessageMedia'
    Local $hOpen = _WinHttpOpen()
    Local $Form = '<form action="' & $Query & '" method="post" enctype="multipart/form-data">' & _
                  '<input type="text" name="chat_id"/>' & _
                  '<input type="text" name="message_id"/>' & _
                  '<input type="file" name="photo"/>' & _
                  '<input type="text" name="caption"/>'
    If $Reply_markup <> Default Then $Form &= '<input type="text" name="reply_markup"/>'
    $Form &= '</form>'
    Local $Response = _WinHttpSimpleFormFill($Form,$hOpen,Default, _
                       "name:chat_id", $ChatID, _
                       "name:message_id", $Message_id, _
                       "name:photo"  , $Path,   _
                       "name:caption", "", _
                       "name:reply_markup", $Reply_markup)

    _WinHttpCloseHandle($hOpen)
    Local $Json = Json_Decode($Response)
    ConsoleWrite("RES:" & $Response & " ______ " & $Json &  @CRLF)
    If Not (Json_IsObject($Json)) Then Return SetError(2,0,False) ;Check if json is valid
    Return __GetFileID($Json,'photo')
EndFunc ;==> _editMessageMedia

$Message_id is on the JSON answer of polling with _GetUpdates(). 

I use like this uploading a pic from the pc:

_editMessageMedia($ChatID, $telegramMsgData[7] , $sPath & $nomeFile, $ikeyb )

and I get this error:

{"ok":false,"error_code":400,"description":"Bad Request: can't parse InputMedia: Media is not specified"}
Link to comment
Share on other sites

  • 3 weeks later...

thank you for the UDF.

but it seems like im having an issue.

Test file for Telegram UDF by LinkOut. (https://github.com/xLinkOut)
This file need a valid ChatID of a Telegram User to send messages to and a valid bot token given by BotFather.
Insert this data in the source code.

! Initializing bot... True

Who am I? Oh, yeah, my name is Project-X, you can find me at @Ray_ProjectXBot. For developers, my Telegram ID is xxxxxxxx
Let's do some test:
    Sending a simple text message. The function _SendMsg return the Message ID: False
    Now I'll forward the same message to you, with the message id saved before: False
    Awesome. Use the other _Send functions to send photos, videos, documents. Each function return the FileID assigned by Telegram.
!       Sending photo: 0
!       Sending video: 
!       Sending audio: 
!       Sending documents: 
!       Sending voice: 
!       Sending sticker: 
!       Sending video note: 
!       Sending location: False
!       Sending contact: False

You can send a 'Chat Action', that mean the user see 'Bot is typing...' or 'Bot is sending a photo...'.

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

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

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.
Don't forget to ? star this repo on GitHub, this mean a lot for me.+>01:54:58 AutoIt3.exe ended.rc:0

any idea?

Link to comment
Share on other sites

  • Developers
9 hours ago, Raywando said:

but it seems like im having an issue.

Great ....  care to share details in case you want assistance with that issue? :) 

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

4 hours ago, Jos said:

Great ....  care to share details in case you want assistance with that issue? :) 

Jos

im not really sure what info you need exactly, but i only modified the test.au3, put my token which i got from @BotFather and added my ChatID which i got from @get_id_bot 

when i try the url below i get 

{"ok":true,"result":[]}

idk if that helps but i thought it might.

https://api.telegram.org/bot<MyBotToken>/getUpdates

if there is anything else i need to share please let me know.

Link to comment
Share on other sites

You must create a chat, i.e. a group, get the chat_id and insert into the autoit prog, then insert the bot as a member of that group. Then you can send your messages with the bot or receive the msg from the group.

With getUpdates to see something, you must first send a msg into that group in which there is your bot.

Edited by frank10
Link to comment
Share on other sites

On 3/2/2019 at 7:13 PM, frank10 said:

You must create a chat, i.e. a group, get the chat_id and insert into the autoit prog, then insert the bot as a member of that group. Then you can send your messages with the bot or receive the msg from the group.

With getUpdates to see something, you must first send a msg into that group in which there is your bot.

thank you

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