The fulfilment response is visible in diagnostic info in the Dialogflow environment. But it's not showing up when I test it in Actions on Google. Anyone who knows how to let it work? Here is my webhook code:
<?php
$method = $_SERVER['REQUEST_METHOD'];
if($method == 'POST'){
$requestBody = file_get_contents('php://input');
$json = json_decode($requestBody);
$text = $json->queryResult->queryText;
$date = (!empty($json->queryResult->parameters->date)) ? $json->queryResult->parameters->date : '';
$environment = (!empty($json->queryResult->parameters->environment)) ? $json->queryResult->parameters->environment : '';
$intent = (!empty($json->queryResult->intent->displayName)) ? $json->queryResult->intent->displayName : '';
$responseText = prepareResponse($intent, $text, $date, $environment);
$response = new \stdClass();
$response->speech = $responseText;
$response->displayText = $responseText;
$response->source = "webhook";
header("Content-type:application/json");
echo json_encode($response);
}
else
{
echo "Method not allowed";
}
function prepareResponse($intent, $text, $date, $environment)
{
return "You said: " . $text . " | I found Intent: " . $intent . " | with parameters: date=" . $date . " environment=" . $environment;
}
?>
Responses for Actions on Google should be in an object under the payload attribute that contains a single attribute google with the AoG response format.
I haven't tested it, and this may not be the best way to build it, but something like the following should work:
$response->payload = array(
"google" => array(
"expectUserResponse" => TRUE,
"richResponse" => array(
"items" => array(
array(
"simpleResponse" => array(
"textToSpeech" => $responseText
)
)
)
)
)
);
Related
we develop mobile app for a website that have gravity form and we can make entry via web api of gravity form, but in website when submit the form it's create new post automatically because form have some post fields and when we add new entry via web api it just add entry not post.
how can we define that this entry must be saved to post via gravity forms web api?
Update:
gravity form can create post via it forms if that form have post fields. read more
and this functionality is just for submission form so you can't access it via web api.
for do this you must add it manually
complete example that must be placed at themes/YOUR_THEME/functions.php:
$api_key = 'your_public_key';
$private_key = 'your_private_key';
//set route
$route = 'entries'; // or 'forms/{formID}/entries'
//creating request URL
$expires = strtotime( '+1 day' );
$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'POST', $route, $expires );
$sig = calculate_signature( $string_to_sign, $private_key );
$url = 'http://your_domain.com/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires;
if(isset($_POST)){
$body = [
[
"form_id"=> "1", // if $route is just 'entries'
'1' => "Post Title" ,
'2' => "Post Content"
]
//,[ another entry ]
];
$response = wp_remote_post($url,['body'=>json_encode($body)]);
if ( is_wp_error( $response ) ) {
wp_send_json_error($response->get_error_message());
} else {
$body = json_decode($response['body'],true);
if($body['status'] === 201){
foreach($body['response'] as $entry_id){ //get each entry ID
$entry = GFAPI::get_entry( $entry_id );
if(!is_wp_error($entry)){
$form = GFAPI::get_form( rgar($entry,'form_id') );
if($form)
GFCommon::create_post( $form, $entry); //Finally add Post.
else
wp_send_json_error("can not find entry form.");
}else
wp_send_json_error($entry->get_error_message());
}
wp_send_json_success("Success!");
}else{
wp_send_json_error($body);
}
}
}else
wp_send_json_error("request body invalid");
$api_key = 'your_public_key';
$private_key = 'your_private_key';
//set route
$route = 'entries'; // or 'forms/{formID}/entries'
//creating request URL
$expires = strtotime( '+1 day' );
$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'POST', $route, $expires );
$sig = calculate_signature( $string_to_sign, $private_key );
$url = 'http://your_domain.com/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires;
if(isset($_POST)){
$body = [
[
"form_id"=> "1", // if $route is just 'entries'
'1' => "Post Title" ,
'2' => "Post Content"
]
//,[ another entry ]
];
$response = wp_remote_post($url,['body'=>json_encode($body)]);
if ( is_wp_error( $response ) ) {
wp_send_json_error($response->get_error_message());
} else {
$body = json_decode($response['body'],true);
if($body['status'] === 201){
foreach($body['response'] as $entry_id){ //get each entry ID
$entry = GFAPI::get_entry( $entry_id );
if(!is_wp_error($entry)){
$form = GFAPI::get_form( rgar($entry,'form_id') );
if($form)
GFCommon::create_post( $form, $entry); //Finally add Post.
else
wp_send_json_error("can not find entry form.");
}else
wp_send_json_error($entry->get_error_message());
}
wp_send_json_success("Success!");
}else{
wp_send_json_error($body);
}
}
}else
wp_send_json_error("request body invalid");
I have an odd problem with this script. I can post directly to it using the URL: "http://example.com/script.php?payer_email=foo&txn_id=9229fjfua822". But trying to post the same data from lets say http://requestmaker.com nothing is showing in the variable(s). I'm using nginx with PHP5.
<?php
$panel_url = 'http://example.com:23462/';
$username = $_GET['payer_email'];
$invoice = $_GET['txn_id'];
$trimmedinvoice = substr($invoice, -6);
$password = $trimmedinvoice;
$max_connections = 1;
$reseller = 0;
$bouquet_ids = array(
1,
2,
3 );
$expirationdays = $_GET['custom'];
$expiration = "+$expirationdays day";
$expiredate = strtotime($expiration);
###############################################################################
$post_data = array( 'user_data' => array(
'username' => $username,
'password' => $password,
'max_connections' => $max_connections,
'is_restreamer' => $reseller,
'exp_date' => $expiredate,
'bouquet' => json_encode( $bouquet_ids ) ) );
$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );
$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=create", false, $context ) );
Echo "<b>Username:</b> <br>";
echo $username;
echo "<br></br>";
echo "<b>Password:<br></b>";
echo $password;
echo "<br></br>";
echo "<b>Expires (in unix time):<br></b>";
echo $expiredate;
?>
Been testing all night and found that adding this code will return the data being passed without problems. So the problem seems to be with the script, not the setup itself. Just can't figure where I'm going wrong.
print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
print "</pre>";
Output from the last block of code posting directly with the URL:
CONTENT_TYPE:
DATA:
string(0) ""
array(0) {
}
Output from the last block of code posting using an external poster like the requestmaker:
CONTENT_TYPE:
text/html<BR />
DATA: <pre>string(35) "payer_email=foo&txn_id=9229fjfua822"
array(0) {
}
POST variables are in $_POST not $_GET (the latter contains the arguments appended to the URI).
You could use $_REQUEST which contains both POST and GET variables.
See this document for more.
Previously i was used http server for my linkedin login. Now I changed https server for my entire site. But now i cannot show login details after changed that. Here i post my function, In this fuction i also changed https. But yet not i show the details. I use this function in codeigniter.
public function login(){
$client_id = $this->config->item('linkedin_app_id');
$redirect_uri = base_url().'linkedinLogin';
if (isset($_GET['error'])) {
echo $_GET['error'] . ': ' . $_GET['error_description'];
} elseif (isset($_GET['code'])) {
$this->loginAccessToken();
$user = $this->login_fetch('GET', '/v1/people/~:(id,firstName,lastName,email-address,picture-url)');//get name
$email = $user->emailAddress;
$user_name = $user->firstName;
$last_name = $user->lastName;
$social_id = $user->id;
$profile_image_url = 'user-thumb.png';
echo "<pre>";print_r($user); die;
if($email != '')
{
$googleLoginCheck = $this->user_model->googleLoginCheck($email);
if($googleLoginCheck > 0)
{
//echo "login";
$getGoogleLoginDetails = $this->user_model->google_user_login_details($email);
//echo "<pre>";print_r($getGoogleLoginDetails);die;
$userdata = array(
'fc_session_user_id' => $getGoogleLoginDetails['id'],
'session_user_email' => $getGoogleLoginDetails['email']
);
//echo "<pre>";print_r($userdata);die;
$this->session->set_userdata($userdata);
if($this->data['login_succ_msg'] != '')
$lg_err_msg = $this->data['login_succ_msg'];
else
$lg_err_msg = 'You are Logged In ...';
$this->setErrorMessage('success',$lg_err_msg);
redirect(base_url());
}
else
{
$google_login_details = array('social_login_name'=>$user_name,'social_login_unique_id'=>$social_id,'screen_name'=>$user_name,'social_image_name'=>'','social_email_name'=>$email,'loginUserType'=>'google');
//echo "<pre>";print_r($google_login_details);die;
//echo "redirect to registration page";
$social_login_name = $user_name;
$this->session->set_userdata($google_login_details);
$firstname = $user_name;
$lastname = $last_name;
$orgPass = time();
$pwd = md5($orgPass);
$Confirmpwd = $orgPass;
$username = $user_name;
$condition = array ('email' => $email);
$duplicateMail = $this->user_model->get_all_details ( USERS, $condition );
$expireddate = date ( 'Y-m-d', strtotime ( '+15 days' ) );
$dataArr = array('firstname'=>$firstname,'lastname'=>$lastname,'user_name'=>$firstname,'group'=>'User','image'=>$profile_image_url,'email'=>$email,'password'=>$pwd,'status'=>'Active','expired_date'=>$expireddate,'is_verified'=>'No','loginUserType'=>'linkedin','google'=>'Yes','created'=>date('Y-m-d H:i:s'));
$this->user_model->simple_insert(USERS,$dataArr);
$lstID = $this->db->insert_id();
//echo $this->db->last_query(); die;
$userdata = array (
'quick_user_name' => $firstname,
'quick_user_email' => $email,
'fc_session_user_id' => $lstID,
'session_user_email' => $email
);
$this->session->set_userdata ( $userdata );
$this->setErrorMessage('success','Registered & Login Successfully');
redirect(base_url());
}
}
else
{
redirect('');
}
}else {
header("Location:https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=$client_id&redirect_uri=$redirect_uri&state=987654321&scope=r_basicprofile%20r_emailaddress%20w_share");
}
}
public function loginAccessToken() {
$params = array(
'grant_type' => 'authorization_code',
'client_id' => $this->config->item('linkedin_app_id'),
'client_secret' => $this->config->item('linkedin_app_key'),
'code' => $_GET['code'],
'redirect_uri' => base_url().'linkedinLogin'
);
// Access Token request
$url = 'https://www.linkedin.com/uas/oauth2/accessToken?' . http_build_query($params);
// Tell streams to make a POST request
$context = stream_context_create(
array('https' =>
array('method' => 'POST',
)
)
);
// Retrieve access token information
$response = file_get_contents($url, false, $context);
// Native PHP object, please
$token = json_decode($response);
// Store access token and expiration time
$_SESSION['access_token'] = $token->access_token; // guard this!
$_SESSION['expires_in'] = $token->expires_in; // relative time (in seconds)
$_SESSION['expires_at'] = time() + $_SESSION['expires_in']; // absolute time
return true;
}
public function login_fetch($method, $resource, $body = '') {
$opts = array(
'https' => array(
'method' => $method,
'header' => "Authorization: Bearer " .
$_SESSION['access_token'] . "\r\n" .
"x-li-format: json\r\n"
)
);
$url = 'https://api.linkedin.com' . $resource;
// if (count($params)) {
// $url .= '?' . http_build_query($params);
// }
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
return json_decode($response);
}
Here look the login() fuction. I print the user details. But i got empty window only
echo "<pre>";print_r($user); die;
But when i use http, i got the user details. Can help me anyone?
Using the SoundCloud PHP wrapper, I can successfully update a song’s title, privacy, genre, tags. But I can't figure out what I'm doing wrong with regard to the streamable property. When I send a true value to track[streamable], it remains false.
Here’s what I’m working with:
<?php
require_once 'Soundcloud.php';
require './globaldatabase.php';
$access_token = $_POST['access_token'];
$trackid = $_POST['trackid'];
$title = $_POST['title'];
$genre = $_POST['genre'];
$tag_list = $_POST['tag_list'];
$privacy = $_POST['privacy'];
$release = $_POST['release'];
$streamable = true;
if($privacy=='disabled'){
$streamable = false;
$privacy = 'private';
}
$client = new Services_Soundcloud($sc_clientid, $sc_clientsecret);
$client->setAccessToken($access_token);
try {
$track = json_decode($client->get('tracks/'.$trackid));
$client->put('tracks/' . $track->id, array(
'track[title]' => $title,
'track[genre]' => $genre,
'track[tag_list]' => $tag_list,
'track[sharing]' => $privacy,
'track[release]' => $release,
'track[streamable]' => $streamable
));
$return = $client->get('tracks/' . $track->id);
$return_array[] = json_decode($return);
echo json_encode($return_array);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
?>
Try setting the track attribute api_streamable to true.
I am using PAYPAL API.
I success calling the setExpressCheckout (after calling this method I got ACK=Success) and therefore get a full link that I can proceed with.
After getting the full link (https://www.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=[SESSION_TOKEN]), the full link represent a page, that includes error.
The error:
This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.
Return to merchant
At this time, we are unable to process your request. Please return to and try another option
Here is my Code:
<?php
/*.
require_module 'standard';
require_module 'standard_reflection';
require_module 'spl';
require_module 'mysqli';
require_module 'hash';
require_module 'session';
require_module 'streams';
.*/
//turn php errors on
//ini_set('track_errors', true);
require_once __DIR__ . "/stdlib/all.php";
require_once __DIR__ . "/SqlManager.php";
/*. array .*/ $body_data = null;
$body_data_txt = "";
/*. string .*/ $htmlpage = "";
/*. array .*/ $keyAr = array();
/*. array .*/ $tokenAr = array();
$response = "";
/*. SqlManager .*/ $sqlm = null;
session_start();
$url = trim('https://api-3t.paypal.com/nvp');
$urlRun = trim('https://www.paypal.com/cgi-bin/webscr');
$body_data = array( 'USER' => *****",
'PWD' => "******",
'SIGNATURE' => "*****",
'VERSION' => "95.0",
'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
'PAYMENTREQUEST_0_AMT' => (string)$_SESSION["AMOUNT"],
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'RETURNURL' => "******",
'CANCELURL' => "******",
'METHOD' => "SetExpressCheckout"
);
$body_data_txt = http_build_query($body_data, '', chr(38));
try
{
$sqlm = new SqlManager(true);
//create request and add headers
$params = array(
'http' => array(
'protocol_version' => "1.1",
'method' => "POST",
'header' => "".
"Connection: close\r\n".
"Content-Length: ".strlen($body_data_txt)."\r\n".
"Content-type: "."application/x-www-form-urlencoded"."\r\n",
'content' => $body_data_txt
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
try {
$fp = fopen($url, 'r', false, $ctx);
} catch(ErrorException $e) {
throw new ErrorException("cannot open url" . $url . " error:" . $e->getMessage());
}
//get response
$response = (string)stream_get_contents($fp);
//check to see if stream is open
if ($response === "") {
throw new Exception("php error message = " . "$php_errormsg");
}
//close the stream
fclose($fp);
$key = explode("&", $response);
$keyAr = array();
foreach ($key as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$keyAr[$tmpAr[0]] = $tmpAr[1];
}
}
if (substr($response, 0, 1) === "<") {
echo $response;
} else {
// Extract the response details.
if((0 == sizeof($keyAr)) || !array_key_exists('ACK', $keyAr) || (string)$keyAr["ACK"] !== "Success") {
if (array_key_exists('L_ERRORCODE0', $keyAr) && array_key_exists('L_LONGMESSAGE0', $keyAr)) {
echo cast("string", htmlspecialchars(urldecode((string)$keyAr["L_ERRORCODE0"]))) . ',' .
cast("string", htmlspecialchars(urldecode((string)$keyAr["L_LONGMESSAGE0"])));
} else {
echo "Unkown server response!";
}
} else {
// ********************************************
$htmlpage = $urlRun . "?cmd=_express-checkout&". "TOKEN=" . (string)$keyAr["TOKEN"]; // ******************* IS THIS LINE OK????
// ********************************************
echo "ok," . $htmlpage;
}
}
}
catch(Exception $e)
{
echo 'Message: ||' .cast("string", str_replace('"', '\\"', $e->getMessage())).'||';
}
?>
the $htmlpage got the full link (see the line with the asterisks remark 'IS THIS LINE OK')
My account is business account.
What may be the cause for the problem?
Seem kind of configuration problem - are there any setups I shall check?
Thanks :)
The problem is that I have opened the paypal page with 'TOKEN=', and I should open by 'token='
(capitalized letter matter).
The line:
$htmlpage = $urlRun . "?cmd=_express-checkout&". "TOKEN=" . (string)$keyAr["TOKEN"];
should be:
$htmlpage = $urlRun . "?cmd=_express-checkout&". "token=" . (string)$keyAr["TOKEN"];
Thanks, anyway :)