This is my first post. Hope I get help here. Thanks for reading.
Short version:
When i send a link to my bot, Telegram show a popup "Open this link .... ?" before open the link.
I want to avoid that. Any ideas?
See also questions
Force closure of the popup on telegram “Open this link?”
Is there a way to send links with telegram bot and show no alert on tap/click?
Long Version:
I have a telegram bot, which I'm sending a message from a Raspberry pi
via PHP. Background is some status notification on my smart home.
Please see code below.
I'm send a telegram message with a link attached with an inline keyboard, so that I can provide a certain responds to my smart home.
In other questions I saw that this is connected to the "parse_mode" html. I tried different modes, however the result is always the same.
Also checked the telegram api documentation for help.
https://core.telegram.org/bots/api#formatting-options
https://core.telegram.org/bots/api#sendmessage
As this is just for myself and running only locally, I don't care about cosmetics or security.
I would appreciate any help or new ideas.
Here is my code for reference
function telegram($message,$maschine) {
if (!isset($maschine)) {
echo "no Maschine for telegram";
exit;
}
if (!isset($message)) {
echo "no Message for telegram"; exit;
}
$website = "https://api.telegram.org/bot" . botToken;
$Keyboard = [
'inline_keyboard' =>
[
[
[
'text' => "test",
'url' => '192.168.1.1/test.php,
]
]
]
];
$encodedKeyboard = json_encode($Keyboard);
$params = [
'chat_id'=>chatId,
'text'=> $message,
'reply_markup' => #$encodedKeyboard,
'one_time_keyboard' => true,
'parse_mode'=> 'html'
];
$ch = curl_init($website . '/sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$jsonresult = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($jsonresult['ok']==false) {
echo "Telegram Error Code: " . $jsonresult['error_code'] . " - ". $jsonresult['description'] . "<br>";
} else {
echo "Telegram message send<br>";
}
}
I more or less found the answer now to my own question:
I haven't found a solution for the inline_keyboard.
If you comment the keyboard feature out and only use the link in the "text" paramater --> Then telegram is not asking for a extra confirmation to open the link.
See upated code below.
So issue solved. At least for me.
$params = [
'chat_id'=>chatId,
'text'=> 'open this link: 192.168.1.1/test.php',
//'reply_markup' => #$encodedKeyboard,
//'one_time_keyboard' => $setting,
'parse_mode'=> 'Markdown'
];
Related
I am trying to track events happening on my client's website(Squarespace) so I can use these events for marketing automation in Active Campaign.
I read through this article: https://help.activecampaign.com/hc/en-us/articles/221870128-An-overview-of-Event-Tracking#an-overview-of-event-tracking-0-0
On how to setup but since I am not an API expert I am finding it difficult to understand as I do not program scripts.
This is the code I was given as an example;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://trackcmp.net/event");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array( "actid" => 23033, "key" => "c12973b078007927842301eff932e7d78b74b3e", "event" => "YOUR_EVENT", "eventdata" => "ANY_DATA", "visit" => json_encode(array( // If you have an email address, assign it here. "email" => "", )), ));
$result = curl_exec($curl);
if ($result !== false) {
$result = json_decode($result);
if ($result->success) {
echo 'Success! ';
} else {
echo 'Error! ';
}
echo $result->message;
}
else {
echo 'CURL failed to run: ', curl_error($curl);
}
Please can someone help me out with a step by step guide on what to do.
From what I've read on Squarespace, they do not give you full control of the website's code. You are on their platform, working with their editor, and can only use their tooling, not 3rd party ones (unless they provide an integration with the 3rd party).
Check out
https://www.squarespace.com/websites/analytics
https://www.squarespace.com/email-marketing
to find out what tools they offer about analytics.
If these are not sufficient for you, you'll need to contact Squarespace for help, requesting what features they are missing (possibly at a cost) and/or move to a traditional web host with either a custom content management system (e.g. WordPress) or a custom one, and maybe hire a web developer to implement an analytics system that has everything you need.
My goal is to be able to use a slash command to open a dialog and process the feedback into a database. I am trying to get the dialog to open but am getting an error regarding the slash command where it says "trigger_id" not found.
My app is set up with an API and the proper OAuth.
I added a slash command to my app with the url of my php page (domain.com/slash.php)
The slash command is set up with the code below.
When I run it from my slack, I get the output of
'{"ok":false,"error":"invalid_arguments","response_metadata":{"messages":["[ERROR] missing required field: trigger_id"]}}'
I have tried some debugging and output the trigger_id to the screen and find that the trigger_id is indeed null. What am I missing to pass this?
I admit that I am new to the slack realm. I have followed (I think) the documentation from the slack site on setting up the app correctly.
Am I missing something with my slack app setup or something in my code that is causing this error message?
Thank you in advance for your time!
<?
$command = $_POST['command'];
$text = $_POST['text'];
$token = $_POST['token'];
$cn = $_POST['channel_id'];
$user_id = $_POST['user_id'];
$triggerid = $_POST['trigger_id'];
// define the dialog for the user (from Slack documentation example)
$dialog = [
'callback_id' => 'validres-3100',
'title' => 'Test',
'submit_label' => 'Submit',
'elements' => [
[
'type' => 'text',
'label' => 'Test Field 1',
'name' => 'field_1'
],
[
'type' => 'text',
'label' => 'Test Field 2',
'name' => 'field_2'
]
]
];
// define POST query parameters
$query = [
'token' => '<my api auth code>',
'dialog' => json_encode($dialog),
'trigger_id' => $triggerid
];
// define the curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://slack.com/api/dialog.open');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// set the POST query parameters
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));
// execute curl request
$response = curl_exec($ch);
// close
curl_close($ch);
var_export($response);
?>
To open dialog box in slack you can use this api "https://slack.com/api/views.open".
With api you need to send trigger id which is valid only for 3 seconds.
Your url will looks like :
"https://slack.com/api/views.open?trigger_id=" + "xxxx.xxxxxxxxx.xxxxxxxxxxxx" + "&view=your data".
with this request you need to send token with your post request like :-
(URL,"POST", { "token" ,"xoxb-xxxxxx-xxxxx-xxxxxxx"});
Need to add view.open API in your slack app also for this use following step:
Use "Bot User OAuth Access Token" , In "OAuth and permissions Tab" Format is xoxb-xxxxx-xxxxx-xxxx. And then add scope "views:open" and reinstall your app in slack. And then try to get open view dialog.
Hope this will be helpful.
I want to send FCM push notifications in specific android users only using their token saved in mysql database as identification. here's my current progress
PHP Script Snippet Code: Report_Status.php (File 1)
//Gets the token of every user and sends it to Push_User_Notification.php
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token = $User_Row['User_Token'];
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = "Your Report has been approved! Please wait for the fire fighters to respond!";
send_notification($User_Token, $message);
}
PHP code for File 2: Push_User_Notification.php
<?php //Send FCM push notifications process
include_once("../../System_Connector.php");
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = API_ACCESS_KEY',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
}
?>
Problem:
The page is always stuck in Report_Status.php every time I ran the
script. It is supposed to go in Push_User_Notification and return to Report_Status once the process is done. Am I wrong in the implementation of calling the
Push_User_Notification.php or the receiving parameters to
Push_User_Notification.php?
P.S.
Here's my full source code of Report_Status.php in case anyone wants to check it: Report_Status.php
I think the problem you may be having is that you are sending a lot of notifications to several devices in short amount of time. I think it might be being picked up as spaming. My suggestion is sending one notification to multiple devices.
Try changing your code in report_status.php to this.
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = "Your Report has been approved! Please wait for the fire fighters to respond!";
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token[] = $User_Row['User_Token'];
}
$tokens = implode(",", $User_Token);
send_notification($tokens, $message);
the idea is that you will collect the user tokens in $User_Token[] array. Then you would comma seperate the tokens and send the message once to all the devices that associate to the tokens. FCM allows you to send to multiple tokens in one go.
updated
$User_Token needs to be an array. so remove the implode. That was my mistake.
Secondly the $message needs to be in the following format.
$message = array(
'title' => 'This is a title.',
'body' => 'Here is a message.'
);
Also another thing to note is that there are 2 types of messages you can send using FCM. Notification Messages or Data Messages. Read more here: https://firebase.google.com/docs/cloud-messaging/concept-options
I dont know if your app is handling the receipt of messages (i dont know if you have implemented onMessageRecieve method) so i would probably suggest making a small change to the $fields array in send_notification function. Adding the notification field allows android to handle notifications automatically if your app is in the background. So make sure you app is in the background when testing. https://firebase.google.com/docs/cloud-messaging/android/receive
$fields = array(
'registration_ids' => $tokens,
'data' => $message,
'notification' => $message
);
So try the code below. I have tried and tested. It works for me. If it does not work. In send_notification function echo $result to get the error message. echo $result = curl_exec($ch); Then we can work from there to see what is wrong. You can see what the errors mean here: https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes
include "../Android_Scripts/Notifications/Push_User_Notification.php";
$message = array(
'title' => 'Report Approved',
'body' => 'Your Report has been approved! Please wait for the fire fighters to respond!'
);
while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
$User_Token[] = $User_Row['User_Token'];
}
send_notification($User_Token, $message);
I am working on a small slack app development. I stuck in one situation. I am using slack dialog to get data from the user and when user enter data
and click on submit button I get an alert message. I don't know what
is it and why it gives an alert. What to do with this? Please note I get
payload response in my interactive component script. And respond to the server with 200. Here is my Response code :
if($type == "dialog_submission")
{
http_response_code(200);
return json_encode(array(
'status' => 200,
'message' => 'ok'
));
$ch = curl_init("https://slack.com/api/chat.postMessage");
$dataSet = http_build_query([
"token" => $authToken,
"channel" => $data['channel']['name'],
"text" => "123",
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataSet);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
Screenshot of alert message
Try something like:
if($type == "dialog_submission") {
return json_encode(array(
'status' => 200,
'message' => ''
));
}
You need to return an empty response to the Slack Dialog, or you will get the error
We had some trouble connecting. Try again?
So you must somewhere have an echo that returns something to the Slack dialog causing the error. You need to remove those. Like the echo $result; at the end.
This error will also occur if your script has a run-time error, since it will then create an automatic response like "error in test.php line 101....". To check for that make sure you have error logging activated and check if there are any errors in the logfile.
You activate error logging by putting these commands at the beginning of your script:
ini_set("log_errors", 1);
ini_set("error_log", "php-errors.log");
You can however return validation errors to Slack, but those must be in a specific format. See this documentation for details.
I have developed a system which will send SMS to the customer after making insert to the database
but the system which I worked on is public ie. when my client asked me to buy the system he must insert his SMS API configuration to send a message to his customers
when I searched on the internet I found that every API have a differnt way to send SMS message
I have account in click tell API but when I send message by curl there is nothing happen
the code is
$url = 'https://platform.clickatell.com/messages/http/send?' . http_build_query(
[
'apiKey' => 'oGjnzDdSRhqdhhgnjFj3ZmzYA==',
// 'api_secret' => '4c98619ffb9af51585',
'to' => '94233698311783',
'content' => 'Hello from Netcom'
]
);
echo($url);echo('<br/>');
echo'https://platform.clickatell.com/messages/http/send?apiKey=oGkmzDdSRgekvjFjaZnzYA==&to=905373545631&content=Test+message+text"';
$ch = curl_init($url);
echo($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
Where my code is wrong and what is the way to send SMS dynamically depending on the client's API info
For quick fix and testing add this in your curl request and check response.(Because url is https)
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
But it is recomonded to downloading a CA root certificate bundle at the curl website and saving it on your server which protect your site
I am not aware of Clickatell, but Aws SNS is quite simple,
$payload = array(
'Message' => $message,
'PhoneNumber' => $mobile,
'MessageAttributes' => $msgAttributes
);
$result = $sns->publish($payload);