Facebook messenger template list not working on messenger app - php

Please I need some help......am developing a Facebook messenger chatbot and I have issue with the List template. When I send the template, the response is received and displays well on the web but on the messenger app, everything gets lumped in one button. Any idea will be appreciated. Thanks.
if($message == "about"){
$answer = ["attachment"=>[
"type"=>"template",
"payload"=>[
"template_type"=>"list",
"elements"=>[
[
"title"=> "Founder",
"image_url"=> "https://www.cloudways.com/blog/wp-content/uploads/Migrating-Your-Symfony-Website.jpg",
"subtitle"=> "Frederick Angel",
"default_action"=> [
"type"=> "web_url",
"url"=> "https://www.cloudways.com/blog/migrate-symfony-from-cpanel-to-cloud-hosting/",
"webview_height_ratio"=> "tall",
// "messenger_extensions"=> true
// "fallback_url"=> "https://peterssendreceiveapp.ngrok.io/"
],
"buttons"=>[
[
"type"=>"postback",
"title"=>"Read about him",
"payload"=>"Frederick Angel",
"webview_height_ratio"=> "tall",
// "messenger_extensions"=>true
],
]
],
[
"title"=>"Concepts?",
"default_action"=> [
"type"=> "web_url",
"url"=> "https://www.cloudways.com/blog/migrate-symfony-from-cpanel-to-cloud-hosting/",
"webview_height_ratio"=> "tall",
// "messenger_extensions"=> true
// "fallback_url"=> "https://peterssendreceiveapp.ngrok.io/"
],
"buttons"=>[
[
"type"=>"postback",
"title"=>"Read about it",
"payload"=>"concepts",
"webview_height_ratio"=> "tall"
],
]
]
]
]];
$template = [
'recipient' => [ 'id' => $senderId ],
'message' => $answer
];
}

Related

Auto-creation of the case part of php Telegram

I have such a code snippet in a Telegram bot in php
case $message == '/nitromonth' || $data_2['callback_query']['data'] == '/nitromonth':
$chat_id = $data['from']['id'];
$method = 'Send a message';
$send_data = [
'text' => $nitromonth,
'reply_markup' => [
'inline_keyboard' => [
[
[
"text" => $translations['ButtonBuy'][$lang],
"callback_data" => '/buy_first_packet_ds'
],
[
"text" => $translations['Repurchase'][$lang],
"callback_data" => '/discord'
],
],
[
[
"text" => $translations['BackCat'][$lang],
"callback_data" => '/products'
],
],
]
]
];
break;
It calls a message with such buttons on command, is there any way to create a .config file for the bot, where it will indicate, for example:
"button[number]" "/commands"
Where [Number] is the ordinal number, 1, 2, 3.. 10, etc.
Where /commands is a command, as indicated in the line
case $message == '/nitromonth' ||$data_2['callback_query']['data'] == '/nitromonth':
there can be nth number of such lines in cfg, each new line generates code above itself when the bot starts, without creating 1000 lines with the same the same code
I'm not a very good php developer, so I'm asking for help

How we can insert header and footer in google docs with google docs api using PHP code

I want to insert header and footer in my google docs with google docs api in PHP code. I am doing it like this-
$requests = new Google_Service_Docs_Request(array(
'createHeader' => [
'type' => 'TITLE',
'sectionBreakLocation' => [
'index' => 0
],
],
)),
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
'requests' => $requests
));
$response = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
but, i am getting this error-
PHP Fatal error: Uncaught Google\Service\Exception: {
"error": {
"code": 400,
"message": "Invalid value at 'requests[5].create_header.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), \"TITLE\"",
"errors": [
{
"message": "Invalid value at 'requests[5].create_header.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), \"TITLE\"",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "requests[5].create_header.type",
"description": "Invalid value at 'requests[5].create_header.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), \"TITLE\""
}
]
}
]
}
}
Please help me out with this, That how we can insert texts in header and footer in google docs using PHP.
In your script, how about the following modification?
Create header:
I thought that the reason of the error message of Invalid value at 'requests[5].create_header.type' (type.googleapis.com/google.apps.docs.v1.HeaderFooterType), \"TITLE\"" is due to 'type' => 'TITLE',. But when I saw your script, $requests is required to be an array. So how about the following modification?
From:
$requests = new Google_Service_Docs_Request(array(
'createHeader' => [
'type' => 'TITLE',
'sectionBreakLocation' => [
'index' => 0
],
],
)),
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
'requests' => $requests
));
To:
$requests = new Google_Service_Docs_Request(array(
'createHeader' => [
'type' => 'DEFAULT',
'sectionBreakLocation' => [
'index' => 0
],
],
));
$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
'requests' => array($requests)
));
Create footer:
In this case, please replace createHeader to createFooter in the above $requests.
Note:
As additional information, when you want to use the first page header and footer, you can use the following request.
$requests = new Google_Service_Docs_Request(array(
'updateDocumentStyle' => [
'documentStyle' => [
'useFirstPageHeaderFooter' => true,
],
'fields' => 'useFirstPageHeaderFooter',
],
));
References:
CreateHeaderRequest
CreateFooterRequest

How to use Google Cloud Healthcare API HttpBody class?

I'm having a hard time using a method setData() of the HttpBody class. I'm passing the parameter to the method as an object, but I recieve an error message.
How do I pass the parameter:
public function create(string $resource, $body)
{
$client = $this->googleClient();
$service = new CloudHealthcare($client);
$parent = "projects/my_project_id/locations/my_location/datasets/my_dataset/fhirStores/repository";
$httpBody = new HttpBody();
$httpBody->setContentType('application/fhir+json;charset=utf-8');
$httpBody->setData([
"resourceType" => "Patient",
"id" => "23434",
"meta" => [
"versionId" => "12",
"lastUpdated" => "2014-08-18T15:43:30Z"
],
"text" => [
"status" => "generated",
"div" => "<!-- Snipped for Brevity -->"
],
"extension" => [
[
"url" => "http://example.org/consent#trials",
"valueCode" => "renal"
]
],
"identifier" => [
[
"use" => "usual",
"label" => "MRN",
"system" => "http://www.goodhealth.org/identifiers/mrn",
"value" => "123456"
]
],
"name" => [
[
"family" => [
"Levin"
],
"given" => [
"Henry"
],
"suffix" => [
"The 7th"
]
]
],
"gender" => [
"text" => "Male"
],
"birthDate" => "1932-09-24",
"active" => true
]);
$data = $service->projects_locations_datasets_fhirStores_fhir->create($parent, $resource, $httpBody);
return $data;
}
Following the error message I get.
The error says I didn't pass the resourceType field, but it was passed:
Google\Service\Exception: {
"issue": [
{
"code": "structure",
"details": {
"text": "unparseable_resource"
},
"diagnostics": "missing required field \"resourceType\"",
"expression": [
""
],
"severity": "error"
}
],
"resourceType": "OperationOutcome"
} in file /usr/share/nginx/vendor/google/apiclient/src/Http/REST.php on line 128
How should I pass the parameter to receive the success message?
Tkanks!
I haven't tried the PHP client libraries specifically, but for most languages you don't want to use the HttpBody class - it's an indication that the method accepts something in the body of the request that is just text from the perspective of the method signature. I would try passing the JSON string directly.

LinkedIn:Media posts not visible on wall after sharing using REST API

I am trying to create a PHP script which shares posts on LinkedIn automatically with the help of zoonman/linkedin-api-php-client SDK https://github.com/zoonman/linkedin-api-php-client. I could share a post without any media and it is visible on my LinkedIn wall. When trying to share a post with an image, the API response returned true with an id urn:li:share:6605357601301553152, but the post is not visible on my wall. I am providing my code for posting media below.
public function postMedia($data,$accessToken){
try{
$mediareturn = $this->client->post(
'assets?action=registerUpload',
[
"registerUploadRequest"=>[
"recipes"=> [
"urn:li:digitalmediaRecipe:feedshare-image"
],
"owner"=> "urn:li:person:**********",
"serviceRelationships"=> [
[
"relationshipType"=> "OWNER",
"identifier"=> "urn:li:userGeneratedContent"
]
]
]
]
);
$uploadUrl = $mediareturn['value']['uploadMechanism']['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest']['uploadUrl'];
$filepath = $this->root_url.'assets/uploads/'.$data['attachment'];
$shell = shell_exec('curl -i --upload-file '.$filepath.' --header "Authorization: Bearer "'.$accessToken.' '.$uploadUrl);
$share = $this->client->post(
'ugcPosts',
[
"author"=> "urn:li:person:**********",
"lifecycleState"=> "PUBLISHED",
"specificContent"=> [
"com.linkedin.ugc.ShareContent"=> [
"shareCommentary"=> [
"text"=> $data['content']
],
"shareMediaCategory"=> 'IMAGE',
"media"=> [
[
"status"=> "READY",
"description"=> [
"text"=> "Center stage!"
],
"media"=> $mediareturn['value']['asset'],
"title"=> [
"text"=> "Test posting"
],
"thumbnails"=> [],
]
]
]
],
"visibility"=> [
"com.linkedin.ugc.MemberNetworkVisibility"=> "PUBLIC"
]
]
);
return $share;
}catch(Exception $e){
throw $e;
}
}
The above code was written referring the official document https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/share-on-linkedin.
Any and all help would be greatly appreciated.

Google Analtyics not registering transactions when using Measurment protocol

I try to send http request to track eCommerce.
I got response http_code=200 but, I can't see any event or transaction.
Code:
$fields_string = '';
$fields = array(
'v' => 1,
'tid' => "UA-xxxxxx-1",
'cid' => $userid,
't' => 'transaction',
'ti' => $transaction_id,
'tr' => $Transaction_revenue,
'ts' => $Transaction_shipping,
'tt' => $tax,
'cu' =>'EUR'
);
Hit:
v=1&t=event&tid=UA-xxxxxx-1&cid=555&uid=123&ti=21&tr=20&tt=5&ts=2&pa=purchase&ec=Checkout&ea=Purchase
what could be the problem?
Thanks a lot.
What makes you think its not working. I ran your hit against debug collect to verify it. Looks good to me.
https://www.google-analytics.com/debug/collect?v=1&t=event&tid=UA-3731463-1&cid=555&uid=123&ti=21&tr=20&tt=5&ts=2&pa=purchase&ec=Checkout&ea=Purchase
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ ],
"hit": "/debug/collect?v=1\u0026t=event\u0026tid=UA-3731463-1\u0026cid=555\u0026uid=123\u0026ti=21\u0026tr=20\u0026tt=5\u0026ts=2\u0026pa=purchase\u0026ec=Checkout\u0026ea=Purchase"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
Did you check the real time reports have you double checked your Tid?
https://www.google-analytics.com/debug/collect?v=1&tid=UA-3731463-1&cid=123&t=transaction&ti=124&tr=1&ts=1&tt=1&cu=EUR
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ ],
"hit": "/debug/collect?v=1\u0026tid=UA-3731463-1\u0026cid=123\u0026t=transaction\u0026ti=124\u0026tr=1\u0026ts=1\u0026tt=1\u0026cu=EUR"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
Could also be something with the values you are sending in the second one.
Apparently I cloud not send transaction because my IP was blocked.

Categories