Jump to content

curl telegram + strange things


aldrovan
 Share

Recommended Posts

hi fellows i try  to send a text like this

data: 30-09-2022

other: blalbalb

etc: xxxxxx

in telegram by curl  i use  this syntax

$Action = "sendMessage"
    $URL = "https://api.telegram.org/bot" & $token & "/" & $Action
    $cicle = UBound($data) / 4
    Local $a = 0, $b = 1, $c = 2, $d = 3
    For $i = 0 To $cicle
        MsgBox(0,'',$data[$a])

        $text= "Data: "& $data[$a]

                MsgBox(0,'',$text)

        Run(@ComSpec & " /c " & @ScriptDir & '\curl\bin\curl.exe commandName -v -X POST --silent --output /dev/null ' & $URL & ' -d chat_id=' & $ChatID & ' -d text='&$text, "", @SW_HIDE) ; don't forget " " before "/c"
        $a += 4
        $b += 4
        $c += 4
        $d += 4
        If $d > UBound($data) Then
            ExitLoop
        EndIf
    Next

the strange things is  if i use  $text= "Data: "& $data[$a] send me only text Data: without a array if $text=  $data[$a]  send me only a data 29-09-2022 but  why  ???

thanks

 

Link to comment
Share on other sites

Because there is a space in the string and you do not put " " around the string.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

sorry again but  i have  also another strange thing  in practical , the  for repeat two time  , i have  this   function

 

Func _TelegramBotCurl($token, $data)

    ;_ArrayDisplay($data)

    $Action = "sendSticker"
    $URL = "https://api.telegram.org/bot" & $token & "/" & $Action
    ;$data="CAACAgQAAxkBAAEF9T1jNpkkuWRDVYKHnPUPFXFBTl0MGwACMQwAAjIXuVEc6LihmiTkbSoE"
    $dataTop = "CAACAgQAAxkBAAEF9T9jNplFM3b-9DDg3zyPZhhpO7eEmQACDiAAAmSKPgABEwY6mWO8PJMqBA"
    Run(@ComSpec & " /c " & @ScriptDir & '\curl\bin\curl.exe commandName -v -X POST --silent --output /dev/null ' & $URL & ' -d chat_id=' & $ChatID & ' -d sticker=' & $dataTop, "", @SW_HIDE) ; don't forget " " before "/c"



    $Action = "sendMessage"
    $URL = "https://api.telegram.org/bot" & $token & "/" & $Action
    $cicle = UBound($data) / 4
    Local $a = 0, $b = 1, $c = 2, $d = 3
    Sleep(3000)
    For $i = 1 To $cicle
        ;MsgBox(0,'',$data[$a])

        $text= "Data:_"& $data[$a]& "%0A" & _
               "Data:_" & $data[$b] & "%0A" & _
                "Data:_" & $data[$c] & "%0A" & _
                "Data:_"& $data[$d]& "%0A" & @CRLF

        Run(@ComSpec & " /c " & @ScriptDir & '\curl\bin\curl.exe commandName -v -X POST --silent --output /dev/null ' & $URL & ' -d chat_id=' & $ChatID & ' -d text='&$text, "", @SW_HIDE) ; don't forget " " before "/c"
        $a += 4
        $b += 4
        $c += 4
        $d += 4
        Sleep(3000)
        If $d > UBound($data) or $i = $cicle Then
            If ProcessExists("curl.exe") Then     ; Check if the internet esplorer process is running.
                ProcessClose("curl.exe")
            EndIf
            ExitLoop

        EndIf
    Next



    $Action = "sendSticker"
    $URL = "https://api.telegram.org/bot" & $token & "/" & $Action
    ;$data="CAACAgQAAxkBAAEF9T1jNpkkuWRDVYKHnPUPFXFBTl0MGwACMQwAAjIXuVEc6LihmiTkbSoE"
    $data = "CAACAgQAAxkBAAEF9T9jNplFM3b-9DDg3zyPZhhpO7eEmQACDiAAAmSKPgABEwY6mWO8PJMqBA"
    Run(@ComSpec & " /c " & @ScriptDir & '\curl\bin\curl.exe commandName -v -X POST --silent --output /dev/null ' & $URL & ' -d chat_id=' & $ChatID & ' -d sticker=' & $dataTop, "", @SW_HIDE) ; don't forget " " before "/c"

EndFunc   ;==>_TelegramBotCurl

in this  function i have  this  array $data with 8 row  with data i subdivide in 2 block with

$cicle = UBound($data) / 4
    Local $a = 0, $b = 1, $c = 2, $d = 3
    Sleep(3000)
    For $i = 1 To $cicle

but  firstime  work good  but  after not exit loop and repeat again two time  o_O why ???

thanks

 

 

Link to comment
Share on other sites

I would use RunWait() and not a fixed Sleep(). So you don't need to use ProcessClose() without knowing what's going on.

Your programming style is a bit strange for me by the way. I would clean up the code and use [($i -1) * 4 + 1] as indexer for line one.

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...