Webhook not posting to URL - php

I have a Webhook I am trying to configure. A user fills out a form, and it is connected to a Webhook as well to send the form data to another location. Doesnt seem to be working, when I submit the form, the webhook destination doesn't seem to be processing/sending the data.
Here is the Json Data:
data.json { "Account_Name": [ "Test Name" ], "Email": [ "test#test.com" ], "Phone": [ "5555555555" ], "camp_id": [ "18052" ], "hs_a_t": [ "1360223458579" ], "ip_address": [ "" ], "referrer": [ "" ], "source": [ "3" ], "time_submitted": [ "07:51 AM UTC" ] }
data.xml <?xml version='1.0'?> <form_data> <Account_Name>Test Name</Account_Name> <Phone>5555555555</Phone> <Email>test#test.com</Email> <camp_id>18052</camp_id> <hs_a_t>1360223458579</hs_a_t> <source>3</source> <referrer/> <ip_address></ip_address> <time_submitted>07:51 AM UTC</time_submitted> </form_data>
extra_data.json { "rapleaf": {} }
extra_data.xml <?xml version='1.0'?> <extra_data> <rapleaf/> </extra_data>
page_id a75948fc-70f6-11e2-8dd8-12313e008101
page_name Test
page_url http://unbouncepages.com/test33333
variant a
Here is the php code the webhook points to:
<?php
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
if (get_magic_quotes_gpc()) {
$unescaped_post_data = stripslashes_deep($_POST);
} else {
$unescaped_post_data = $_POST;
}
$form_data = json_decode($unescaped_post_data['data_json']);
/*******************************
PARSE DATA FROM UNBOUNCE
*******************************/
$email_address = $form_data->email[0];
$page_id = $_POST['page_id']; //Unbounce Page ID
$page_url = $_POST['page_url']; //Unbounce Page URL
$variant = $_POST['variant']; //Unbounce Page Variant
function mytheme_post_to_another_script($form)
{
// Rewrite the post variables
$post = array(
'Account_Name' => $_POST['name'], // Change iphorm_X_X to name field unique ID
'Email' => $_POST['email_address'], // Change iphorm_X_X to email field unique ID
'Phone' => $_POST['phone_number'], // Change iphorm_X_X to phone field unique ID
'Website_URL' => $_POST['iphorm_1_4'],
'Camp_ID' => $_POST['Camp_ID'],
'Source' => $_POST['Source'],
'Email_List_ID' => $_POST['Email_List_ID'],
'hs_a_t' => $_POST['hs_a_t']
);
// Create a new cURL resource
$ch = curl_init();
// Set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, 'http://Reports.rankupmedia.com/Client/Sales/Lead/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
// Grab URL and pass it to the browser
curl_exec($ch);
// Close cURL resource, and free up system resources
curl_close($ch);
}
?>

Related

How to send a Embedded Webhook using PHP [Discord]

I am trying to send a Webhook to a Discord channel when a User fills out a form on my website, I would really like it to be embedded, however I am having trouble doing that. I have managed to post the Webhhook fine using "content", however I just cannot get it embed it.
$Embed = {
"username": "Kick Report",
"embeds": [{
"fields": [
{
"name": "Victim",
"value": "Change Victim Later",
"inline": true
},
{
"name": "Reason",
"value": "Change Reason Later!",
"inline": true
},
{
"name": "Caller",
"value": "Change Caller Later"
},
{
"name": "Date",
"value": "Change Date Later"
}
]
}]
};
$data = array("content" => $Embed, "Kick Report" => "Webhooks");
$curl = curl_init("https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxxxxxxxx");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
return curl_exec($curl);
Try this code:
<?php
// Replace the URL with your own webhook url
$url = "https://discordapp.com/api/webhooks/0000000/ABCDEFGH....";
$hookObject = json_encode([
/*
* The general "message" shown above your embeds
*/
"content" => "A message will go here",
/*
* The username shown in the message
*/
"username" => "MyUsername",
/*
* The image location for the senders image
*/
"avatar_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg",
/*
* Whether or not to read the message in Text-to-speech
*/
"tts" => false,
/*
* File contents to send to upload a file
*/
// "file" => "",
/*
* An array of Embeds
*/
"embeds" => [
/*
* Our first embed
*/
[
// Set the title for your embed
"title" => "Google.com",
// The type of your embed, will ALWAYS be "rich"
"type" => "rich",
// A description for your embed
"description" => "",
// The URL of where your title will be a link to
"url" => "https://www.google.com/",
/* A timestamp to be displayed below the embed, IE for when an an article was posted
* This must be formatted as ISO8601
*/
"timestamp" => "2018-03-10T19:15:45-05:00",
// The integer color to be used on the left side of the embed
"color" => hexdec( "FFFFFF" ),
// Footer object
"footer" => [
"text" => "Google TM",
"icon_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
],
// Image object
"image" => [
"url" => "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
],
// Thumbnail object
"thumbnail" => [
"url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
],
// Author object
"author" => [
"name" => "Alphabet",
"url" => "https://www.abc.xyz"
],
// Field array of objects
"fields" => [
// Field 1
[
"name" => "Data A",
"value" => "Value A",
"inline" => false
],
// Field 2
[
"name" => "Data B",
"value" => "Value B",
"inline" => true
],
// Field 3
[
"name" => "Data C",
"value" => "Value C",
"inline" => true
]
]
]
]
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init();
curl_setopt_array( $ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $hookObject,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
]
]);
$response = curl_exec( $ch );
curl_close( $ch );
?>
Source: https://www.reddit.com/r/discordapp/comments/83itgm/does_anyone_know_how_to_send_embeds_from_php_to_a/

how to setup this simple Elasticsearch Mapping in Elasticsearch-PHP?

Given in the end of the question is an terminal command showing a simple Elasticsearch mapping. I need to set up this kind of mapping for an index using Elasticsearch-PHP. And I need to do this at the time when I am indexing the data.
I know how to index in Elasticsearch-PHP. It will be something like
for($i = 0; $i < 100; $i++) {
$params['body'][] = [
'index' => [
'_index' => 'my_index',
'_type' => 'my_type',
]
];
$params['body'][] = [
'my_field' => 'my_value',
'second_field' => 'some more values'
];
}
$responses = $client->bulk($params);
My question is that how will I set up a Mapping, corresponding to the particular Mapping given below in the elasticsearch-PHP format (I believe it will become an associative array, but I am not sure of further details)?
This is the example ES Mapping, that I want to convert to the format used in PHP:
PUT _template/packets
{
"template": "packets-*",
"mappings": {
"pcap_file": {
"dynamic": "false",
"properties": {
"timestamp": {
"type": "date"
},
"layers": {
"properties": {
"ip": {
"properties": {
"ip_ip_src": {
"type": "ip"
},
"ip_ip_dst": {
"type": "ip"
}
}
}
}
}
}
}
}
}
If you don't update your mapping - you don't have to put mapping each time you re-index data into elasticsearch. But if you do, of you create index with new name you can do this:
$put = [
'mappings' => [
// your mapping here
],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yourHost:9200/yourIndex');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($put));
curl_exec($ch);
or you can use elasticsearch package:
$params = [
'index' => 'yourIndex',
'body' => [
'mappings' => [
// your mapping here
]
]
];
$response = $client->indices()->create($params);

Telegram PHP inline_keyboard

I'm trying to create a bot which send an inline_keyboard when in receive the text "/start", the problem is that i can't see the response when i use this function to send the keyboard
function sendKeyboard($chat_id, $text) {
$keyboard = ['inline_keyboard' => [
['text':'Yes'],
['text':'No']
],
'resize_keyboard' => true,
'one_time_keyboard' => true,
'selective' => true
];
$keyboard = json_encode($keyboard);
$url = $GLOBALS[website] . "/sendMessage?chat_id=".$chat_id."&
reply_markup=".$keyboard."&text=".urlencode($text);
file_get_contents($url);
}
Can somebody understand how to solve this problem?
Inline Keyboard buttons is array of array of Button, and resize_keyboard, one_time_keyboard and selective is not for inline keyboard, it's parameters for Reply Keyboard.
Your code only have array of Button, and Button only have text field, it need to add callback_data or url, or you will get error.
You have better to see reference about details.
function robot($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
robot('sendmessage', [
"chat_id" => $chat_id,
'message_id'=>$messageid,
"text" => "* buttonwith out link *
",
'reply_markup' => json_encode([
"one_time_keyboard" => true,
'inline_keyboard'=> [
[
['text' => "button 1", 'callback_data' => "buttoncode-39500"]
]
]
])
]);

Forbidden error 403 in Unification Engine API while sending message

I am using #unificationengine API to send message on facebook.
Details I have given while registering my APP on facebook:
site url : http://localhost:3000
Email adress and other required details
In unificationengine API I have used all the curls mentioned in their documentation step by step as follows:
1. Created user using API key and Secret
2. Added connection
3. test connection
4. Refresh connection
5. Send message
All 4 gave 200 success code but send message gives 403 fobidden error.
The curl I am using for this is as below:
$post_msg = json_encode(
array(
'message' =>
array(
'receivers' =>
array(
array(
'name' => 'Me',
'address' => 'https://graph.facebook.com/v2.5/me/feed',
'Connector' => 'facebook'
),
),
'sender' =>
array('address' => ''),
'subject' => 'Hello',
'parts' =>
array(
array(
'id' => '1',
'contentType' => 'text/plain',
'data' => 'Hi welcome to UE',
'size' => 100,
'type' => 'body',
'sort' => 0
),
),
),
)
);
$ch = curl_init('https://apiv2.unificationengine.com/v2/message/send');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD,'3f43c37b-a066-4cc4-a3be-33faf72d6a21:2722fc72d-5d347-4a3a-a82b-0c1ss51aafb4');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_msg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
return ['label' =>$response];
I am trying to figure this. But no success.
Again I like to mention that I am using this on localhost, could that be the reason for forbidden error? If so then facebook graph api from which we get access token should also give such error.
Earlier I have posted this question, here also I didn't find right solution. I added Curl options that is mentioned in comment of my question there but it didn't changed the things.
Any help would be highly appreciated.
Error Message:
{\"Status\":{\"facebook\":{\"status\":403,\"info\":\"Forbidden:
\"}},\"URIs\":[]}
UPDATE
Below is the json I get when I run me/permissions in facebook graph API explorer:
{
"data": [
{
"permission": "user_birthday",
"status": "granted"
},
{
"permission": "user_about_me",
"status": "granted"
},
{
"permission": "user_status",
"status": "granted"
},
{
"permission": "user_posts",
"status": "granted"
},
{
"permission": "email",
"status": "granted"
},
{
"permission": "manage_pages",
"status": "granted"
},
{
"permission": "publish_actions",
"status": "granted"
},
{
"permission": "public_profile",
"status": "granted"
}
]
}
I have resolved this problem:
public function facebookSharing($access_token) {
$app = new UEApp(env('UNIFICATION_APP_KEY'), env('UNIFICATION_APP_SECRATE'));
$user = new UEUser('unification_userkey', 'unification_usersecret');
$connection = $user->add_connection('FACEBOOK', "facebook", $access_token);
$options = array(
"receivers" => array(
array(
"name"=> "Me"
)
),
"message"=>array(
"subject"=>'testing',
"body"=> 'description',
"image"=> 'use any image url',
"link"=>array(
"uri"=> 'any web site url',
"description"=> "",
"title"=>"Title"
)
)
);
$uris = $connection->send_message($options);
}
Please use your keys like
facebook accesstoken
UNIFICATION_APP_KEY (its your unification keys)
UNIFICATION_APP_SECRATE (its your unification keys)
If this will not work then please let me know.
Can you please confirm if the "Connector" name that you have given is correct?
While I tried your sample code that you provided, I could sent the message to facebook via UE.
Can you please provide the exact error message that is returned while you execute the command?

Simple php function to send an email with Mandrill

What is the easiest way to send an email via Mailchimp's Mandrill service (using the API).
Here's the send method: https://mandrillapp.com/api/docs/messages.html#method=send
Here's the API wrapper: https://bitbucket.org/mailchimp/mandrill-api-php/src/fe07e22a703314a51f1ab0804018ed32286a9504/src?at=master
But I can't figure out how to make an PHP function that will send and email via Mandrill.
Can anyone help?
We also have an official API wrapper for PHP, which is available on Bitbucket or via Packagist, which wraps the Mandrill API for you.
If your Mandrill API key is stored as an environment variable, here's a simple example of sending using a template, with some merge variables and metadata:
<?php
require 'Mandrill.php';
$mandrill = new Mandrill();
// If are not using environment variables to specific your API key, use:
// $mandrill = new Mandrill("YOUR_API_KEY")
$message = array(
'subject' => 'Test message',
'from_email' => 'you#yourdomain.example',
'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
'to' => array(array('email' => 'recipient1#domain.example', 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.example',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))));
$template_name = 'Stationary';
$template_content = array(
array(
'name' => 'main',
'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, thanks for signing up.'),
array(
'name' => 'footer',
'content' => 'Copyright 2012.')
);
print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
?>
Mandrill take HTTP POST requests for all of their API methods, and they take your input as a JSON string. Here's a basic example of sending an email. It uses cURL to do the HTTP request:
$uri = 'https://mandrillapp.com/api/1.0/messages/send.json';
$postString = '{
"key": "YOUR KEY HERE",
"message": {
"html": "this is the emails html content",
"text": "this is the emails text content",
"subject": "this is the subject",
"from_email": "someone#example.com",
"from_name": "John",
"to": [
{
"email": "blah#example.com",
"name": "Bob"
}
],
"headers": {
},
"track_opens": true,
"track_clicks": true,
"auto_text": true,
"url_strip_qs": true,
"preserve_recipients": true,
"merge": true,
"global_merge_vars": [
],
"merge_vars": [
],
"tags": [
],
"google_analytics_domains": [
],
"google_analytics_campaign": "...",
"metadata": [
],
"recipient_metadata": [
],
"attachments": [
]
},
"async": false
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($ch);
echo $result;
// Simply Send Email Via Mandrill...
require_once 'Mandrill.php';
$mandrill = new Mandrill($apikey);
$message = new stdClass();
$message->html = "html message";
$message->text = "text body";
$message->subject = "email subject";
$message->from_email = "address#example.com";
$message->from_name = "From Name";
$message->to = array(array("email" => "recipient#example.com"));
$message->track_opens = true;
$response = $mandrill->messages->send($message);
This is the most basic piece of code I could give you, I just craft it seconds ago for a client and it's working smooth.
require_once 'path/to/your/mandrill/file/Mandrill.php';
try {
$mandrill = new Mandrill('your-API-key');
$message = array(
'html' => $htmlMessage,
'subject' => $subject,
'from_email' => $fromEmail,
'from_name' => $fromName,
'to' => array(
array(
'email' => $toEmail,
'name' => $toName,
'type' => 'to'
)
)
);
$result = $mandrill->messages->send($message);
print_r($result);
} catch(Mandrill_Error $e) {
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
throw $e;
}
Also check their send method for more options like headers, meta-data, attachments etc. https://mandrillapp.com/api/docs/messages.php.html#method-send
Include the PHP API: https://bitbucket.org/mailchimp/mandrill-api-php
Code: https://mandrillapp.com/api/docs/messages.php.html#method-send
You can use ZF's autoloading for including the wrapper class or Composer: https://mandrillapp.com/api/docs/index.php.html

Categories