I am currently using Amazon AWS SNS to send SMS to customers.
SMS works fine however I would like to simply display a success or error message when the form has been submitted depending on the outcome.
result after form submit on successful message below. I can see that statusCode with int(200) means that it was sent successfully. How can I fetch this and use it to display success or error message?
object(Aws\Result)#117(2){
[
"data": "Aws\Result": private
]=>array(2){
[
"MessageId"
]=>string(36)"f12f2261-5e13-54e8-b72e-37s26fd3c348"[
"#metadata"
]=>array(4){
[
"statusCode"
]=>int(200)[
"effectiveUri"
]=>string(35)"https://sns.eu-west-1.amazonaws.com"[
"headers"
]=>array(4){
[
"x-amzn-requestid"
]=>string(36)"716dase5-f048-5d35-8af0-sf36ce583d95"[
"content-type"
]=>string(8)"text/xml"[
"content-length"
]=>string(3)"294"[
"date"
]=>string(29)"Tue, 18 Jun 2019 19:31:28 GMT"
}[
"transferStats"
]=>array(1){
[
"http"
]=>array(1){
[
0
]=>array(0){
}
}
}
}
}[
"monitoringEvents": "Aws\Result": private
]=>array(0){
}
}
php code:
if(isset($_POST['gateeway'])){
$sender_id = $_POST['sender_id'];
$message = $_POST['message'];
$topic = 'arn:aws:sns:eu-west-1:52732446504:Testing';
try {
$result = $sns->publish([
'TargetArn' => $topic,
'Message' => $message,
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => $sender_id,
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => 'Promotional',
]
]
]);
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
}
You can get the status code like this
$metaInfo = $result->get('#metadata');
if($metaInfo ['statusCode'] === 200){
echo "Message Sent";
}
Related
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
this question was asked before and was ignored, if you have a solution for it then your contribution is valuable, is there any way to change the default sound of the FCM notification if I'm using the below code, changing "sound"=>"arrive" to soundtrack path is not working?
thank you
public function toFcm($notifiable) {
$message = new FcmMessage();
$notification = [
'body' => trans('lang.notification_your_order', ['parcel_id' => $this->parcel->id, 'order_status' => $this->parcel->parcelStatus->status]),
'image' => Config::get('app.url').'/uploads/parcel.png',
'icon' => Config::get('app.url').'/uploads/parcel.png',
"title" => "Order Updated",
"content_available" => true,
"priority" => "high",
"sound"=>"arrive",
'id' => 'orders',
];
$data = [
'click_action' => "FLUTTER_NOTIFICATION_CLICK",
'id' => 'orders',
'status' => 'done',
'message' => $notification,
];
$message->content($notification)->data($data)->priority(FcmMessage::PRIORITY_HIGH);
return $message;
}
Ensure that the name of the sound matches the name of the sound installed inside the res/raw folder, then ensure your request is correctly formatted
example: "filename.mp3"
{
"token": "client_notification_token", <- or topic
"notification": {
"title": "Push notification title",
"body": "Push body",
"sound": "filename", <-- points to src/res/raw/filename.mp3
}
...
}
Source: https://medium.flatstack.com/migrate-to-api-26-push-notifications-with-custom-sound-vibration-light-14846ebc9e96
Notifications are sent, no problem mais I wish to have a badge on the notifications it is never used, I went through all the firebase documentation nothing to do. As is the keyword field.
Package used : edujugon/push-notification:4.5
$devices[] = $deviceData['id'];
$push = new PushNotification('fcm');
$push->setMessage([
'notification' => [
'title' => $this->title,
'body' => $this->body,
'badge' => $this->badge,
],
])
->setApiKey($this->apiKeyFirebase)
->setDevicesToken($devices)
->send();
With this array sent, I am not receiving the notification under IOS, so the feedback from the ios server tells me that the notification has been sent, there must be a problem with the keys to my array that I am sending, I don’t haven't found, would anyone know?
$devices[] = $deviceData['id'];
$push = new PushNotification('apn');
$push->setMessage([
'aps' => [
'alert' => [
'title' => $this->title,
'body' => $this->body,
],
'badge' => $this->badge,
],
])
->setConfig($this->getConfig())
->setDevicesToken($devices)
->send();
Yes, the feedback :
object(stdClass)#157 (3) {
["success"]=>
int(1)
["failure"]=>
int(0)
["tokenFailList"]=>
array(0) {
}
}
It tells me sucess true but i am not getting the notification on ios, it is not visible
With the library sly/notification-pusher, i received push notif ios but i have not title :(
$messages = [$this->body];
$params = ['title' => $this->title];
$pushNotificationService = new ApnsPushService(
$certificatePath, $passPhrase, PushManager::ENVIRONMENT_PROD
);
$response = $pushNotificationService->push($devices, $messages, [
'aps' => [
'alert' => [
'title' => $this->title,
'body' => $this->body,
],
'badge' => $this->badge,
]
]);
I´m trying to integrate the RESTFUL API of ActiveCampaing to my Laravel environment, but I haven’t been so luckier, I'm using GuzzleHttp to make the requests, this is the error image and my code:
$client = new \GuzzleHttp\Client([‘base_uri’ => ‘https://myaccount.api-us1.com/api/3/’]);
$response = $client->request('POST', 'contacts', [
'headers' => [
'Api-Token' => 'xxx',
'api_action' => 'contact_add',
],
'json' => [
'email' => 'test2021#test.com',
'first_name' => 'Julian',
'last_name' => 'Carax',
]
]);
echo $response->getStatusCode(); // 200
echo $response->getBody();
Hope you could help me! :D
you are not sending the data in correct format,
from the docs https://developers.activecampaign.com/reference#contact
{
"contact": {
"email": "johndoe#example.com",
"firstName": "John",
"lastName": "Doe",
"phone": "7223224241",
"fieldValues":[
{
"field":"1",
"value":"The Value for First Field"
},
{
"field":"6",
"value":"2008-01-20"
}
]
}
}
So create an array with key contact.
$contact["contact"] = [
"email" => "johndoe#example.com",
"firstName" => "John",
"lastName" => "Doe",
"phone" => "7223224241",
"fieldValues" => [
[
"field"=>"1",
"value"=>"The Value for First Field"
],
[
"field"=>"6",
"value"=>"2008-01-20"
]
]
];
Use try catch blocks as then you can catch your errors
try{
$client = new \GuzzleHttp\Client(["base_uri" => "https://myaccount.api-us1.com/api/3/"]);
$response = $client->request('POST', 'contacts', [
'headers' => [
'Api-Token' => 'xxx',
'api_action' => 'contact_add',
],
'json' => $contact
]);
if($response->getStatusCode() == "200" || $response->getStatusCode() == "201"){
$arrResponse = json_decode($response->getBody(),true);
}
} catch(\GuzzleHttp\Exception\ClientException $e){
$error['error'] = $e->getMessage();
if ($e->hasResponse()){
$error['response'] = $e->getResponse()->getBody()->getContents();
}
// logging the request
\Illuminate\Support\Facades\Log::error("Guzzle Exception :: ", $error);
// take other actions
} catch(Exception $e){
return response()->json(
['message' => $e->getMessage()],
method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500);
}
You can check at the API docs that the fields email, first_name, last_name are under a contact node.
So make a contact array, put these fields inside and you should be fine.
The fields for first and last name are written line firstName and lastName - camelCase, not snake_case like you did.
Official php client
You should probably use the official ActiveCampaign php api client - that would make your life easier.
https://github.com/paypal/Checkout-PHP-SDK
I downloaded this and i have tested it with simple php but i don't know where to put these files in which folder for CodeIgniter
https://github.com/paypal/Checkout-PHP-SDK/blob/develop/samples/CaptureIntentExamples/RunAll.php
`Creating an Order
Code:
// Construct a request object and set desired parameters
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
"intent" => "CAPTURE",
"purchase_units" => [[
"reference_id" => "test_ref_id1",
"amount" => [
"value" => "100.00",
"currency_code" => "USD"
]
]],
"application_context" => [
"cancel_url" => "https://example.com/cancel",
"return_url" => "https://example.com/return"
]
];
try {
// Call API with your client and get a response for your call
$response = $client->execute($request);
// If call returns body in response, you can get the deserialized version from the result attribute of the response
print_r($response);
}catch (HttpException $ex) {
echo $ex->statusCode;
print_r($ex->getMessage());
}`.