How to send a large message to api.telegram.org - telegram

I'm having trouble sending large messages via bot telegrams. During the search for the problem, I threw off all the extra binding and tested it with curl.
In the case of sending a message with text up to about 1500, everything works, I sent it like this:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "1100ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas "asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasasadsas"
In the case of sending a large message, it stops working, in this case I send a text of 2200 characters in size:
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id = <ID_CHATA> -d text = "2200ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas asadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasas adsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsadsasasadsadsasasadsadsasasadsasasadsasasadsasasadsasasadsasasadsasasasasasasasasasasasadsasasadsasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
Using the -vvvvvv switch for curl, I saw the following details: In the first case (when the message is small and sending is triggered) I see:
Expect: 100-continue HTTP / 1.1 100 Continue HTTP / 1.1 200 OK
In the second case (when I send a large message and the sending does not work) I see:
Expect: 100-continue HTTP / 1.1 100 Continue Empty reply from server Connection #0 to host api.telegram.org left intact Closing connection #0

There seems to be an error in the second CURL request. the -d param requires a string;
curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d "chat_id=<ID_CHATA>" -d "text='200ertyikgnfdhgmcndgbtowewe'"
Also you close the string before the last char, curl doesn't like that;
" sasasasasasasasasasasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsasadsas
If I edit your second command to use -d "", I can send it as expected.
Even with a message of 2578 chars works just fine.
Google tels me there is an 4096 UTF8 char limit; Git
Telegram even send an TOO_LONG if the text param is too long ;) So
Edit based on comment;
Full command for bash;
curl -s -X POST https://api.telegram.org/bot123456:abcdefghijk/sendMessage -d "chat_id=123456" -d "text='Test'"
If this does not work for you, please show the error you receive after running the command

Related

How can I send the content of the file to HTTP Event Collector in Splunk?

I am using a script that gives me some data in json format, I want to send this data to splunk.
I can store the output of the script in a file but how can I send it to HTTP Event Collector?
Couple of things I tried but did not work:
FILE="output.json"
file1="cat answer.txt"
curl -k "https://prd-pxxx.splunkcloud.com:8088/services/collector"  -H "Authorization: Splunk XXXXX"  -d  '{"event": "$file1", "sourcetype": "manual"}'
-----------------------------------------------------------
curl -k "https://prd-pxxx.splunkcloud.com:8088/services/collector"  -H "Authorization: Splunk XXXXX"  -d  '{"event": "#output.json", "sourcetype": "manual"}'
curl -k "https://prd-p-w0gjo.splunkcloud.com:8088/services/collector"  -H "Authorization: Splunk d70b305e-01ef-490d-a6d8-b875d98e689b"   -d '{"sourcetype":"_json", "event": "#output.json", "source": "output.json}
-----------------------------------------------------------------
After trying this I understand that it literally sends everything specified in the event section. Is there a way I can send the content of the file or use a variable?
Thanks in advance!
(Note - I haven't tried this specifically, but it should get you close)
According to Docs.Splunk on HTTP Event Collector Examples #3, it would seem you can do something very similar to this:
curl -k "https://mysplunkserver.example.com:8088/services/collector/raw?channel=00872DC6-AC83-4EDE-8AFE-8413C3825C4C&sourcetype=splunkd_access&index=main" \
-H "Authorization: Splunk CF179AE4-3C99-45F5-A7CC-3284AA91CF67" \
-d < $FILE
Presuming the content of the file is formatted correctly, it should go straight in.
How is the file being created? Is it in a Deployment App on a managed endpoint? If so, it will likely be simpler to setup a scripted input for the UF to run on whatever schedule you choose.

Google Apps Script: testing doPost() with cURL

I have created a very basic Google Apps Script. Here is my doPost() and doGet():
function doPost(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function doGet(e) {
return respond(JSON.stringify({result: "Hello world!"}));
}
function respond(response) {
return ContentService
.createTextOutput(response)
.setMimeType(ContentService.MimeType.JSON)
}
I have deployed the app with a new version. It is set to run as me but everyone can run it including anonymous.
I am testing the endpoint by running cURL from the command line, and for GET it works as expected:
Request -
curl -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Response -
{"result":"Hello world!"}
But for POST:
Request -
curl -H "Content-Length: 0" -D "p=p" -X POST -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
Response -
Sorry, unable to open the file at this time.
Please check the address and try again.
As you can see from the command, I had to manipulate things a bit to get this far: including dummy data, adding a content-length header, and adding the -L flag to consume the redirect.
However, I am stuck. Why can't it "find the file"? Why does it think there is a file?
I suspect you'll need to send data.
This works (I got {"result":"POST request received!"}):
curl -H 'Content-Type: application/json' -d {} -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec
As does this:
curl -d "" -L https://script.google.com/macros/s/AKfycbxYxgMfMkR6hGI5UO2Gn8tg369oqsy_W41-olb0Do1y8gOjaNvm/exec

What is curl doing with -d and -X GET?

I'm looking to this snippet of code:
curl -X GET 'https://api.newrelic.com/v2/applications/1622/metrics/data.json' \
-H 'X-Api-Key:30f4ec24a1f7dd9998a536b05840b17f7d42c7c1' -i \
-d 'names[]=EndUser&names[]=EndUser/Apdex&values[]=call_count&values[]=average_response_time&values[]=score&summarize=true'
from "Listing your app ID and metric data".
But curl's man page only talks about -d/--data in the context of POST requests, so, what's really happening here in terms of the HTTP request sent to the server?
-d with GET request just sends a query string, however the endpoint where data are sent must be set to consume application/x-www-form-urlencoded content type - have just checked that.
In general it's weird and I wouldn't implement it in such a way.
When such query is sent to java servlet - the body is accessible via.. getInputStream() method [sic!].

Using curl to send unsafe url characters in request url

I am sending a curl request pointing to an url containing unsafe characters in it like /test/#/test1.html
I tried below possible ways but was not working. The Url ends when it sees a # in it and the remaining part is not processed. I took a packet capture and found that the url which is sent by curl is just http://<someIP>testsite/ and not http://<someIP>testsite/#/file.html
curl -v -X 'GET' "http://<someIP>/testsite/#/file.html" -D header.txt -o body.txt
curl -v -X 'GET' 'http://<someIP>/testsite/#/file.html' -D header.txt -o body.txt
Could somebody help in answering how to escape the # or how to make curl to send this complete URL ?
What's after # is never sent to the server in the HTTP request. That can only be read through some client side code (js for example). There is no way of making Curl send that.
I am not sure if this helps, but you can try to encode # char to a URL "safe version": %23
Here you can find more useful information: http://www.url-encode-decode.com/

How do you create a user using RESTServer in Drupal?

Using REST Server 6.x-2.0-beta3, I'm trying to understand how to post to user.save.
curl -d 'XX' -v http://localhost/services/rest/service_user/save
I've tried to replace XX with:
account{'name':'myname','pass':'mypassword','mail':'my#email.org'}
account = {'name':'myname','pass':'mypassword','mail':'my#email.org'}
account="name=myname,pass=mypassword,mail=myemail.org"
account=name=myname,pass=mypassword,mail=myemail.org
account=myname,mypassword,myemail.org
But none of these seems to be right and finding any documention regarding this is next to impossible.
I've also tried the following:
curl -H "Content-Type: application/json" -d 'account={"name":"myname","pass":"mypassword","email":"123"}' -v http://localhost/services/rest/service_user/save
The error I get in this case is:
HTTP/1.0 406 Not Acceptable: Missing required argument account
Hi I also just started working with this module and wondering how to create content using JSON.
Just been able to create a simple node using this:
Post URL: http://path-to-site/services/rest/node
Request Header: Content-Type: application/json
Request Body: {"type":"story","title":"REST Test","body":"REST using JSON"}
I think you're using the wrong URL
I figured it out:
curl -H “application/x-www-form-urlencoded” -d "sessid=xxxx" -d "account[name]=MyName&account[pass]=mypass&account[mail]=myemail#gmail.com&account[conf_mail]=myemail#gmail.com" -v http://path-to-site/services/rest/service_user/save
You only have to add -d "sessid=xxxx" if you have configured Services to require a session. Make sure in that case to replace xxxx with your actual session id (from system.connect).

Resources