How to send a message with button in shell to Telegram bot? - bash

I'm using this and works. But how to put a button blew the message? I tried a lot and still got no idea.
Sorry i forgot to tell it's about Telegram bot api. I want to send a message with button blew.
function sendadmin(){
if [ "$admin_id" -ne "$chat_id" ]; then
curl -s \
-d parse_mode="MarkdownV2" \
-d text="$stext" \
-d chat_id="$admin_id" \
-d -sendChatAction="videos" \
-d reply_markup="" \
https://api.telegram.org/bot$bot_token/sendMessage
fi
}
stext="||Hello darling||"
sendadmin
I tried solution of this. And it's return Bad Request: can't parse reply keyboard markup JSON object error.

reply=$(cat <<-EOF
{
"inline_keyboard": [
[
{
"text": "Button1",
"callback_data": "lt"
},
{
"text": "Button1",
"callback_data": "rt"
}
],
[
{
"text": "Button3",
"callback_data": "ls"
}
]
]
}
EOF
)
Using car <<EOF EOF to give that json format to a variable and then use it like reply_markup="$reply" . I just found out this way.

Related

AutoML Vision: Error: ImportData stopped due to too many errors

I selected to create a dataset in the AutoML Vision UI like so:
I get this: Error: ImportData stopped due to too many errors.
Notice that it tells me that I have errors in my csv file, but it does not tell me what errors are, so how can I debug?
I tried this:
>cat operation-get-status.sh
#!/bin/bash
if [ $# -ne 1 ]; then
printf "usage: get-training-status.sh [operation-id]\n"
exit 1
fi
export OPERATION_ID="$1"
#export OPERATION_ID="ICN21697762462531584"
source set-vars.sh
curl -X GET \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
https://automl.googleapis.com/v1beta1/projects/$PROJECT_ID/locations/$REGION_NAME/operations/operation-id
But the response is not very helpful:
>./operation-get-status.sh IOD2963854538949263360
{
"error": {
"code": 400,
"message": "List of found errors:\t1.Field: name; Message: Required field is invalid\t",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "name",
"description": "Required field is invalid"
}
]
}
]
}
}
Which required field is invalid?
I go the same error on my GUI with uploaded CSVs. Tried to upload a single annotation from one video. Got the following error:
Cannot move files across regions. Please use a regional bucket in the
same location and with same storage class as AutoML. Required
Location: us-central1, required location type: Region, required
storage class: Standard.
After changing the type of bucket to the recommended settings, the upload was successful.

How to read response of a JIRA REST API

Using the Atlassian documentation, I'm able to create a new JIRA ticket using curl command. I want to understand how to read the response of this command into a variable? Essentially i want to store the JIRA ticket ID into a variable that can be used in other scripts.
Reference Link: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/
_SAMPLE_CODE_
curl -D- -u charlie:charlie -X POST --data '{
"fields": {
"project":{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/
_SAMPLE_RESPONSE_
{
"id":"39000",
"key":"TEST-101",
"self":"http://localhost:8080/rest/api/2/issue/39000"
}
From the above log, I want to understand how can we fetch the "key" (i.e. JIRA number or JIRA ID) from response (essentially stdout) into a variable.
you can use jq command line tool to extract value from json:
#!/bin/bash
key=$(curl -s -u charlie:charlie -X POST --data '{
"fields": {
"project":{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/|jq -r .key)
echo "key: $key"
jq command is not installed by default on linux systems.
you will need to install it manually:
sudo apt install jq
sudo yum install jq

Bash Loop Through URLs Issue

I'm using cURL request to google safe browsing API to check for any of my requested site is malicious or not. When i'm issuing the following command
$curl -H "Content-Type: application/json" -X POST -d ' { "client": { "clientId": "Test", "clientVersion": "1.0.0" }, "threatInfo": { "threatTypes": ["MALWARE", "SOCIAL_ENGINEERING","THREAT_TYPE_UNSPECIFIED","UNWANTED_SOFTWARE","POTENTIALLY_HARMFUL_APPLICATION"], "platformTypes": ["WINDOWS","PLATFORM_TYPE_UNSPECIFIED","ANY_PLATFORM"], "threatEntryTypes": ["URL"], "threatEntries": [ {"url":"hxxp://bookmyroom.pk/assets/timepicker/f.exe"} ] } }' https://safebrowsing.googleapis.com/v4/threatMatches:find?key=AIzaSyD1IMgjaHEza6e9m_jwtjBgPmJX0IMKKIs
Caution: I have "xx"ed instead "tt" for the http string. This site might be a potential malicious site.So do not open it using browser.
I'm getting JSON response as
{
"matches": [
{
"threatType": "UNWANTED_SOFTWARE",
"platformType": "ANY_PLATFORM",
"threat": {
"url": "hxxp://bookmyroom.pk/assets/timepicker/f.exe"
},
"cacheDuration": "300.000s",
"threatEntryType": "URL"
}
]
}
Caution: I have "xx"ed instead "tt" for the http string. This site might be a potential malicious site.So do not open it using browser.
When i'm doing the same in loop
#check.sh
for i in $(cat malsite.txt); do
content="$(curl -H "Content-Type: application/json" -X POST -d ' { "client": { "clientId": "Test", "clientVersion": "1.0.0" }, "threatInfo": { "threatTypes": ["MALWARE", "SOCIAL_ENGINEERING","THREAT_TYPE_UNSPECIFIED","UNWANTED_SOFTWARE","POTENTIALLY_HARMFUL_APPLICATION"], "platformTypes": ["WINDOWS","PLATFORM_TYPE_UNSPECIFIED","ANY_PLATFORM"], "threatEntryTypes": ["URL"], "threatEntries": [ {"url":"$i"} ] } }' https://safebrowsing.googleapis.com/v4/threatMatches:find?key=AIzaSyD1IMgjaHEza6e9m_jwtjBgPmJX0IMKKIs)"
echo "$i"
echo "$content"
done
#malsite.txt
"hxxp://bookmyroom.pk/assets/timepicker/f.exe"
Caution: I have "xx"ed instead "tt"ing for the http string.This site might be a potential malicious site.So do not open it using browser.
I'm not getting any results. It just returns empty result.
#Result of /.check.sh :
{}
Not sure , Where i'm making mistakes. Any thoughts ?

Sending push notifications to all users

This may be a silly question, but I cannot find a way to send push notifications to all users with Parse.com. I can send notifications to specific channels though.
I tried with
channels: []
but this yields an error.
What's the exact JSON to send push notifications to all users? I'm using the REST API.
Below is an example to send to default [all users] or no channels essentially.
{"data": { "alert": "Alert Message", "sound": "somesoundfile", "badge": "Increment" },"where": { "deviceType": "ios" }}
You can check out their documentation for other tags they support like parseVersion, appName, appVersion etc etc
Edit
To send to all devices you simply don't include the where statement: That was just an example for further customization. Because platforms handle notifications differently and offer different functionalities not all instances are translated. However, here is an example to target all platforms without prejudice:
'{ //not mandatory but just another visual for customizing
"channels": [
"Some Channel"
],
"data": {
"alert": "Alert Message", //not platform specific
"badge": "Increment", //platform specific iOS
"sound": "somesoundfile", //platform specific iOS
"title": "We Pushed to Everyone!" //platform specific Android
}
}'
vb:
postString = "{""where"": {""deviceType"": ""android""}, ""data"": { ""alert"": """ + pushMessage + """}}"`
c#:
postString == "{\"where\": {\"deviceType\": \"android\"}, \"data\": { \"alert\": \"" + pushMessage + "\"}}"
Just include "where" and no conditions.
{
"where": {
},
"data": {
"alert": "Willie Hayes injured by own pop fly."
}
}
The full curl commands:
curl -X POST \
-H "X-Parse-Application-Id: YOURID" \
-H "X-Parse-REST-API-Key: YOURKEY" \
-H "Content-Type: application/json" \
-d '{
"where": {
},
"data": {
"alert": "Willie Hayes injured by own pop fly."
}
}' \
https://api.parse.com/1/push

Parse batch upload API, what does error code 107 mean?

Why can't I add objects using Parse batch bulk import API?
curl -X POST \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-REST-API-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '{
"requests":[
{
"method":"POST",
"path":"1/classes/Store",
"body":{
"storeNumber":3466,
"storeLocation":{
"__type":"GeoPoint",
"latitude":-88.481369,
"longitude":44.263837
},
"storeAddress":"4733 W. GRANDE MARKET DR. GRAND CHUTE WI 54913 US"
}
},
...
{
"method":"POST",
"path":"1/classes/Store",
"body":{
"storeNumber":119,
"storeLocation":{
"__type":"GeoPoint",
"latitude":-122.171134,
"longitude":37.444756
},
"storeAddress":"165 STANFORD SHOPPING CTR PALO ALTO CA 94304-1409 US"
}
}
]
}' \
https://api.parse.com/1/batch
{"code":107,"error":"Method 'POST' to '1/classes/Store' not supported in batch operations."}
I have created a 'Store' object with matching column names/types but can't any any rows with the batch API.
From looking at the documentation I would guess it is because your path is invalid.
You need an extra "/" at the front, so /1/classes/Store instead of 1/classes/Store.

Resources