Did I discover a bug in Telegram? - linux

I use a Telegram bot to incorporate weather alerts from a local weatherservice into my homeautomation system. Today I discovered a weird problem because the message containing the weather alert wasn't sent. If I try this in bash on Linux:
output="Nationaal Hitteplan";curl "https://api.telegram.org/botxxxxxxxxx:longsecuritycode/sendMessage?chat_id=xxxxxxxxx&text=$output"
(I removed my personal tokens in the above command of course...)
then I get a 400 Bad Request and the message is not sent.
If I change output="Nationaal Hitteplan" to output="Nationaal hitteplan" then the message is send as it is supposed to be.
I don't see what's wrong here. The term Nationaal Hitteplan is basically a set of advisories about what to do in hot weather. It has no negative meaning associated with it but apparently Telegram detects a problem.
Does someone have a solution for this except from changing the term as described above?

Url's that contains special characters like a space should be url-encoded.
Use the following curl command to let curl let the encoding:
token='xxxxxxxxx:longsecuritycode';
output="Nationaal Hitteplan";
curl -G \
--data-urlencode 'chat_id=1234567' \
--data-urlencode "text=${output}" \
"https://api.telegram.org/bot${token}/sendMessage"
How to urlencode data for curl command?

Related

How do I substitute my values in a post request?

I have links .php how do I substitute my values in all parameters using curl post?
Provided that I do not know what the parameters are in these php links, curl should determine for itself what parameters are in the post request and substitute my values.
If I know the parameter, then I can send it to the links like this:
while read p; do
curl $p -X POST --connect-timeout 18 --cookie "" --user-agent "" -d "parametr=helloworld" -w "%{url}:%{time_total}s\n"
done < domain.txt > output.txt
And if I do not know the parameters, what should I do? How to make curl automatically substitute values into parameters? For example, the value: "hello world" provided that I did not know "parameter"
It's simply not possible. curl is a client program and has no way of knowing or finding out which request parameters are supported by a server or which are not.
Unless of course, the API is properly documented and available as an OpenAPI/Swagger specification for example. If it isn't, you're out of luck.

How can I query all records with timestamp older than 30 days using cURL?

I want to fetch all records (from Solr) with a timestamp older than 30 days via cURL command.
What I have tried:
curl -g "http://localhost:8983/solr/input_records/select?q=timestamp:[* TO NOW/DAY-30DAYS]"
I do not understand why this does not work but it does not fetch anything. It simply returns nothing. If I replace '[* TO NOW/DAY-30DAYS]' with an actual value, it will retrieve that record.
Additional relevant information, this is how to delete all records older than 30 days (it works). Again, I do not want to delete, rather just fetch the data.
curl -g "http://localhost:8983/solr/input_records/update?commit=true" -H "Content-Type: text/xml" --data-binary "<delete><query>timestamp:[* TO NOW/DAY-30DAYS]</query></delete>"
Thanks in advance!
This error is happening because you don't have proper URL encoding for your request. Most likely the problem is spaces - need to replace them with %20, same applies to other symbols
Try this:
curl -g "http://localhost:8983/solr/input_records/select?q=timestamp:[*%20TO%20NOW/DAY-30DAYS]
A further addition to Mysterion's answer,
Since you are doing this using curl, you are facing the issue of the URL encoding.
If you just mention
http://localhost:8983/solr/input_records/select?q=timestamp:[* TO NOW/DAY-30DAYS]
in your browser (chrome or others)
the Url encoding is automatically handled by the browser and you would get your response as expected.

Couchdb replication hangs and doesn't proceed

I'm trying to replicate some couchdb databases. It works perfectly fine for all, except for one. It seems to always stay stuck at some point in the replication, and the terminal forever stays on hold and doesn't return.
I have no idea where the problem comes from, I imagine it could be one specific document that is problematic, but I don't know how I could check and debug that.
Also, I noticed that if I use replicator in futon, it seems to be working and replicate. But I need to be able to do it from the command line.
Any idea where the problem could be coming from or/and how to debug it?
This is the command I'm using:
curl -X POST http://127.0.0.1:5984/_replicate -d '{"source":"http://user:password#127.0.0.1:5984/origin-db-name", "target":"http://user:password#127.0.0.1:5984/target-db-name"}' -H "Content-Type: application/json"
and here is the output I get when running: curl "http://user:password#127.0.0.1:5984/_active_tasks":
[
{
"pid":"<0.351.0>",
"checkpoint_interval":5000,
"checkpointed_source_seq":1007,
"continuous":false,
"doc_id":null,
"doc_write_failures":0,
"docs_read":0,
"docs_written":0,
"missing_revisions_found":0,
"progress":59,
"replication_id":"4ec403b2de1d9c546182252369f1d96e",
"revisions_checked":187,
"source":"http://user:*****#127.0.0.1:5984/origin-db-name/",
"source_seq":1693,
"started_on":1531010162,
"target":"http://user:*****#127.0.0.1:5984/target-db-name/",
"type":"replication",
"updated_on":1531010188
}
]

pushbullet - The param 'file_url' has an invalid value

I'm trying to use curl to send an image to a device.
this is the code :
#!/bin/bash
curl --header 'Access-Token: d78sdf8bd8bv6d98bd7d6df6b' \
--header 'Content-Type: application/json' \
--data-binary '{"type":"file","title":"Test IMG SEND","body":"Sending Dragon from Debian 8","file_name":"dr1.jpg","file_type":"image/jpeg","file_url":"https://dl2.pushbulletusercontent.com/HJGFC56597ggiyui78698GYGUFI7865/dr1.jpg"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
and this is what I got from the previous upload :
{"data":{"acl":"public-read","awsaccesskeyid":"JSUH(=Y£GhHUIOG898787","content-type":"image/jpeg","key":"HJGFC56597ggiyui78698GYGUFI7865/dr1.jpg","policy":"ecvjksdblvuio3ghuv393783230cgfgsaidfg3","signature":"hjveirvhj34veupiv34'vvg3vg78"},"file_name":"dr1.jpg","file_type":"image/jpeg","file_url":"https://dl2.pushbulletusercontent.com/HJGFC56597ggiyui78698GYGUFI7865/dr1.jpg","upload_url":"https://upload.pushbullet.com/upload-legacy/yVayDlcd
To me, it seems ok, but obviously there is something wrong. Can anyone point me to a solution?
EDIT :
I'm sorry, the problem is that the answer from pushbullet is that "The param 'file_url' has an invalid value" and I'm not able to understand where is the problem, becouse I just copied the file_url from the previous answer from the upload-request, which should be -> file_url":"https://dl2.pushbulletusercontent.com/HJGFC56597ggiyui78698GYGUFI7865/dr1.jpg ...
This error isn't clear as to what's actually invalid about the file_url request. What it should say is, "The file url you specified points to a file that does not yet exist". In other words you need to make sure the file is actually uploaded first before you can link to it.
Their docs aren't great. I had the same issue and finally stumbled upon the answer. This is actually a 3-part process:
1) POST https://api.pushbullet.com/v2/upload-request – It wasn't immediately obvious, but this is requesting access to upload your file to Push Bullet's AWS S3 Bucket. Use the data in the response for the next step.
2) POST https://upload.pushbullet.com/upload-legacy/yVayDlcd – (This should be the value from upload_url from Step 1) Everything in the data object should be posted along with the file to the upload_url in the response. The expected response should be a 204 with no content. This means it was successful.
3) POST https://api.pushbullet.com/v2/pushes – Finally now that the file exists in Push Bullet's system you can push using the file_url value from Step 1.
Hopefully this explanation adds some clarity to their docs.

Apache Stanbol sentiment analysis and sentence detection not working

I am using Apache Stanbol. It works for enhancing the text, however when I tried sentiment analysis and sentence detection, it doesn't work.
I tried this code
curl -v -X POST -H "Accept: text/plain" -H "Content-type: text/plain; \
charset=UTF-8" --data "Some text for analysis" \
"http://localhost:8081/enhancer/engine/sentiment-wordclassifier"
But it gives blank { } output, I tried changing the header attributes but no luck.
am I missing something? Do I need to do some configuration first?
I even tried adding analyzer in the enhancer chain but the same blank output, also tried REST API for opennlp-sentence, but it didn't work.
I guess you are sending data to the wrong endpoint... usually calls to the enhancer need to be done to all chains:
http://host/stanbol/enhancer
or to a concrete chain:
http://host/stanbol/enhancer/chain/<name>
The enhancer results couldn't be serialized as plain text, but in any of the RDF serialization supported by Stanbol. So the Accept header would need to be any of those, text/turtle for instance.
Further details at the documentation: http://stanbol.apache.org/docs/trunk/components/enhancer/#RESTful_API

Resources