Patoshi パトシ
Patoshi パトシ

Reputation: 23535

Telegram API using curl in windows throws error of "message text is empty"

I'm running the following command and I get the below error saying text is empty. But its not. I also tried POST and it still does the same error. Any ideas?

curl.exe -k https://api.telegram.org/bot0000:xxxxx/sendMessage?chat_id=333333&text=yooo

{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}'text' is not recognized as an internal or external command, operable program or batch file.

Upvotes: 0

Views: 1586

Answers (1)

Technoob1984
Technoob1984

Reputation: 172

How did you get Curl to work in Windows? My guess is a Pearl Bash hack. Okay so here is what I found in the past doing this. When you use Curl with Windows Powershell, it doesn't really know how to handle the contents. Example: When you make an API call, like "get all machine id's", you might get a list of 100 values. Usually, you would do something like 'Grep' for the name you need, then you pass the 'id' value to a variable and use that to affect the target. What I found happening was the string of 'text' wasn't being passed as a string object, but rather some sort of machine type object. In a nutshell, you end up having to transform the data, then you have to figure out how to search it. It gets yucky really fast.

Solution: Invoke-WebRequest

While this module takes a little getting use to, when you use it you can pass the values as Powershell Rich Objects and use the $variable.value sort of syntax that everyone loves with Powershell.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1

#chat_id variable creation. This might need to be in the header, I don't know this API but wanted to show the example 
$body = @{ 
            chat_id = 333333
            text = yooo 
         } 
#Example. Actual code may vary. 
$message = @{Invoke-RestMethod "https://api.telegram.org/ `
    - Headers @{Authorization = "bot0000 xxxxx"} `
    - Body $body `
    - Method  Get }
#now we can use $message to see what's available.
#we can then use $message.whatever to view the responses. 

Upvotes: 0

Related Questions