Laravel - How to change FCM default notification tune - php

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

Related

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

Data array to send Push Notification in project PHP for android / ios

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,
]
]);

Telegram Inline keyboards PHP

I would like to know how to change the text when clicked button attached to it (Inline keyboards). It's in a telegram channel.
Something like this but with my code below (no need for more options).
The code I have now:
$data = [
'text' => 'choose options yes or no',
'chat_id' => '-100234234234'
];
$keyboard = array(
"inline_keyboard" => array(
array(
array(
"text" => "Yes",
"callback_data" => "myCallbackData"
),
array(
"text" => "No",
"callback_data" => "myCallbackData"
)
)
)
file_get_contents("https://api.telegram.org/bot$token/sendMessage?" . http_build_query($data) . "&parse_mode=html&reply_markup=$keyboard");
After sending the message;
Remember the message_id returned by Telegram
Call /getUpdates to get the callback_data of pressed button
Use /editMessageText to update the first message
Example;
<?php
// Create data
$data = http_build_query([
'text' => 'Yes - No - Stop?',
'chat_id' => '1234567890'
]);
// Create keyboard
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "Yes",
"callback_data" => "yes"
],
[
"text" => "No",
"callback_data" => "no"
],
[
"text" => "Stop",
"callback_data" => "stop"
]
]
]
]);
// Send keyboard
$url = "https://api.telegram.org/bot$token/sendMessage?{$data}&reply_markup={$keyboard}";
$res = #file_get_contents($url);
// Get message_id to alter later
$message_id = json_decode($res)->result->message_id;
// Continually check for a 'press'
while (true) {
// Call /getUpdates
$updates = #file_get_contents("https://api.telegram.org/bot$token/getUpdates");
$updates = json_decode($updates);
// Check if we've got a button press
if (count($updates->result) > 0 && isset(end($updates->result)->callback_query->data)) {
// Get callback data
$callBackData = end($updates->result)->callback_query->data;
// Check for 'stop'
if ($callBackData === 'stop') {
// Say goodbye and remove keyboard
$data = http_build_query([
'text' => 'Bye!',
'chat_id' => '1234567890',
'message_id' => $message_id
]);
$alter_res = #file_get_contents("https://api.telegram.org/bot$token/editMessageText?{$data}");
// End while
break;
}
// Alter text with callback_data
$data = http_build_query([
'text' => 'Selected: ' . $callBackData,
'chat_id' => '1234567890',
'message_id' => $message_id
]);
$alter_res = #file_get_contents("https://api.telegram.org/bot$token/editMessageText?{$data}&reply_markup={$keyboard}");
}
// Sleep for a second, and check again
sleep(1);
}
Note:
This example is written based on OP's code, just to show the idea of altering an inline_keyboard.
This code is purely as an example, there should be a lot more error checking etc...
Based on the comment, I've included a while true to keep on checking for new press.

Send message via socket to a specific client with PHP Socket.IO

I need to send a message to a client connected to a socket server but I need it to only be sent to a person, and not a broadcast as such. I have read that with the function to() of socket.IO it can be but I have implemented it in several ways and I do not get it, I send it to all.
this is my code
...
$socket->on('new message', function($message) use($socket)
{
$socket->emit("new message", array(
"username" => $socket->username,
"action" => "me",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "user", "time" => date('H:i'), "message" => $message ]
)
);
//I NEED HELP HERE, PLEASE
$socket->broadcast->emit("new message", array(
"username" => $socket->username,
"action" => "chat",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "", "time" => date('H:i'), "message" => $message ]
));
});
...
From the Socket.IO cheatsheet:
// sending to individual socketid (private message)
io.to(`${socketId}`).emit('hey', 'I just met you');
So for you, it's something like:
//I NEED HELP HERE, PLEASE
io->to($socketId)->emit("new message", array(
"username" => $socket->username,
"action" => "chat",
"message" => [ "from" => $socket->username['WP_USER_DATA']['guid'], "type" => "", "time" => date('H:i'), "message" => $message ]
));
Note: you need to store (in array) the ids ($socket->id) of the clients when they connected, and use the one you need as $socketId in the example above.

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