I am using JavaScript SDK - v2.1.2 :
My Query : How to send push notification with custom gcm parameters in android device using JavaScript.
I am trying to send push notification to android devices with my JavaScript code but in our app we are using third party receiver called CleverTap for notification.
Following are the mandatory parameters for CleverTap receiver:
"wzrk_pn"
"wzrk_sound"
"nt"
"nm"
"wzrk_dl" which I need to send as custom parameters.
Following is my code for Push Notification :
var pushCustomParams = {
message: 'Message received from Bob',
wzrk_pn: 1,
wzrk_sound: 1,
nt: 'Revofit',
nm: 'This msg is from application',
wzrk_dl: ''
}
var params = {
notification_type : 'push',
push_type : 'gcm', // 'gcm' is for Android, 'apns' - for iOS.
user : { ids: [14411551] }, // recipients.
environment : 'development', // environment, can be 'production' as well.
message : QB.pushnotifications.base64Encode(JSON.stringify(pushCustomParams)), // See how to form iOS or Android spesific push notifications
};
QB.pushnotifications.events.create(params, function(err, response) {
if (err) {
console.log(err);
} else {
// success
console.log(response);
}
});
Logs generated after executing the above code is as follows:
{
"notification": {
"registration_ids": ["dFCRdN7MJD0:APA91bFsaOdorqhvRyMuUGH-Ds8Z_EB6pQWHpQIYy5YVUefwYFwqK39E5BsLtJ2cHYDLv9mPXDQc4mAQRhJTdM2unUgy6-kmWSWMorp0ZSbBL1EdjFZLiorh4LQT3JR454dqEP1bL2_l"],
"delay_while_idle": false,
"data": {
"message": "{\"message\":\"Message received from Bob\",\"wzrk_pn\":1,\"wzrk_sound\":1,\"nt\":\"Revofit\",\"nm\":\"This msg is from application\"}",
"collapse_key": "event7637817"
},
"priority": "high",
"time_to_live": 86400
},
"log": [{
"device_token": null,
"created_at": "2016-06-30T14:26:46Z",
"delivered_at": "2016-06-30T14:26:47Z",
"failed_at": null,
"error_code": null,
"error_description": null
}]
}
But when I tried to send push notification from admin panel with my customized channel setting of GCM Parameters it worked fine.
Log generated for notification from admin panel :
{
"notification": {
"registration_ids": ["eShiPWpBngA:APA91bFzFeaB0LryAt9FmEJ9xl2KHWhZWlfzpYhng4KONN60yr3ySl2R58Eye-qSmhzQ56T2Fyuzr0Yg4y1VWMIm20LH74U7BWO_Az7MgogBD2IGvmWEKvJWWgVH6sD-3wP_gaIgJEAY"],
"delay_while_idle": false,
"data": {
"message": "hii",
"wzrk_pn": "1",
"nm": "New message",
"nt": "revofit",
"collapse_key": "event7632938"
},
"priority": "high",
"time_to_live": 86400
},
"log": [{
"device_token": null,
"created_at": "2016-06-30T08:17:25Z",
"delivered_at": "2016-06-30T08:17:26Z",
"failed_at": null,
"error_code": null,
"error_description": null
}]
}
I am unable to rectify my mistake
Kindly Help me out with this.
Sorry for my bad English. I tried my best.
Since we weren't able to get the solution as required we changed the GCM receiver.
Related
I'm working on a TypeScript Azure Function that has an Azure Service bus topic as its output. I can send messages with it without any problem, but I cannot set any metadata as custom property on the message.
I've tried using an object with the same interface as the ServiceBusMessage from the Service Bus Javascript SDK, like this:
import { AzureFunction, Context, HttpRequest } from "#azure/functions";
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
const message = {
body: "my message content",
applicationProperties: { key: "value" },
};
context.bindings.myTopic = message;
};
export default httpTrigger;
But the message is sent as-is, and the applicationProperties is not taken into account. I cannot see them on the Azure Portal in the Service Bus Explorer. The content of the message will be the JSON version of the message object.
I've tried with the extension bundles 3 and 4, without success.
I'm using this function.json file:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "myTopic",
"type": "serviceBus",
"queueName": "myTopic",
"connection": "SERVICE_BUS_CONNECTION_STRING",
"direction": "out"
}
],
"scriptFile": "../dist/servicebus-writer/index.js"
}
And this host.json file:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}
How can I set those custom properties?
As of today, there is no way to set metadata using bindings in non-C# languages. The workaround would be to use the Service Bus SDK directly to send out messages.
There is this feature request that you could up vote to gain more traction.
I am able to send my current item as an attachment , but i am running into a problem where if there are any inline images within my current item, These do not display properly when i open my current item as an attachment from my newly sent/received mail. I understand that the image src is incorrect after sending my original email as an attachment, but im not sure how to rectify this or if this is expected behaviour because i have missed something.
My aim is to forward my current item/email as it appears, as an outlook item to the recipients mailbox.
Im wondering is there an error in how i have set up my json which i post to the Graph API to send mail ? i will post it below incase anything stands out as being set up wrong. Thanks in advance!
var email = client.api('/me/messages/' + restID).get();
var attachments = client.api('/me/messages/' + restID + '/attachments').get()
const sendMail = {
message: {
subject: 'This contains my original email',// forwardMailSubject,
body: {
contentType: "Text",
content: 'Test' // forwardMailBody
},
toRecipients: [
{
emailAddress: {
address: 'test12321#outlook.com' //forwardMailbox
}
}
],
attachments: [
{
'#odata.type': "#microsoft.graph.itemAttachment",
'name': "attachment",
'contentType': "html",
'item': {
"#odata.type": "#microsoft.graph.message",
"id": email.id,
"createdDateTime": email.createdDateTime,
"lastModifiedDateTime": email.lastModifiedDateTime,
"receivedDateTime": email.receivedDateTime,
"sentDateTime": email.sentDateTime,
"hasAttachments": true,
"internetMessageId": email.internetMessageId,
"subject": "Reminder - please bring laptop",
"importance": "normal",
"conversationId": email.conversationId,
"isDeliveryReceiptRequested": false,
"isReadReceiptRequested": false,
"isRead": false,
"isDraft": false,
"webLink": email.webLink,
"body": email.body,
"sender": email.sender,
"from": email.from,
"toRecipients": email.toRecipients,
"attachments": attachments
}
}
]
}
};
client.api('/me/sendMail')
.post(sendMail);
Steps:
Acquire: success, got resourceId
Start: success, got sid
query: first got success but then, code 404
From the browser, I have joined with 2 users in a channel test1 and uids are 100 and 101.
For recording, I got resourceId for recording using uid 99 (On backend side)
//Accquire
let reqBody = {
"cname": 'test1',
"uid": '99',
"clientRequest": {}
};
Then I hit start API.
//start
let reqBody = {
"cname": 'test1',
"uid": 99,
"clientRequest": {
"token": channelRecorderToken,
"storageConfig": {
"secretKey": ("awsSecretKey"),
"region": storageRegion,
"accessKey": ("awsAccessKey"),
"bucket": ("awsBucket"),
"vendor": storageVendor,
"fileNamePrefix": [
"RECORDINGS"
]
},
}
};
AWS settings are correct, I checked multiple times. For generating token I used this,
let channelRecorderToken = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, userId, role, privilegeExpiredTs);
QUERY RESPONSE:
// RESPONSE 1
{
"resourceId": "resourceId",
"sid": "sid",
"serverResponse": {
"status": 4,
"fileList": "",
"fileListMode": "string",
"sliceStartTime": 0
}
}
// RESPONSE 2: When I again hit query API after 5-10 seconds
{
"resourceId": "resourceId",
"sid": "sid",
"code": 404
}
Want to set up the webhook on my pc and not on google cloud project like the guide is sugesting, and I'm not quite sure how to.
This is the guide: https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation
It says to create a index.js with the following code in it
/*
* HTTP Cloud Function.
*
* #param {Object} req Cloud Function request context.
* #param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
response = "This is a sample response from your webhook!"
//Default response from the webhook to show it's working
res.setHeader('Content-Type', 'application/json');
//Requires application/json MIME type
res.send(JSON.stringify({ "speech": response, "displayText": response
//"speech" is the spoken version of the response, "displayText" is the visual version
}));
};
Never seen exports. before. The guide wants me to do something with 'google functions' and make one called hellohttp or something. Trying to figure out how to do it without google cloud projects.
I installed Node.js and created that file. I set the webhook url to https://my_ip/index.js but doesn't work. Not really sure what to do
this is the JSON I get
{
"id": "9c244834-3ee9-4291-98fd-aab8e975fb1f",
"timestamp": "2018-02-22T23:11:34.067Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "weather TOMORROW in VIRGINIA",
"action": "",
"actionIncomplete": false,
"parameters": {
"date": "2018-02-24",
"geo-city": "Virginia"
},
"contexts": [],
"metadata": {
"intentId": "44486050-dfd5-4c35-bcbf-4e168379df28",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 5006,
"intentName": "Weather"
},
"fulfillment": {
"speech": "I don't know about the weather for 2018-02-24 in Virginia. Sorry!",
"messages": [
{
"type": 0,
"speech": "I don't know about the weather for 2018-02-24 in Virginia. Sorry!"
}
]
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Webhook response was empty.",
"webhookTimedOut": false
},
"sessionId": "9cdbd5bc-403e-4840-8970-e420f27d23e2"
}
I am trying Firebase Cloud Messaging. It's awesome and all, but I am having the hardest time getting it to work for me.
The problem I am facing is with the service worker, here is my firebase-messaging-sw.js :
console.log('Service worker is loaded!');
self.addEventListener('install', function(event) {
console.log('Service Worker is being installed.');
});
self.addEventListener('activate', function(event) {
console.log('Service Worker is being activated.');
});
importScripts('https://www.gstatic.com/firebasejs/3.6.5/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.6.5/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': ' ... '
});
var messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload){
console.log('Received background message: ', payload);
return self.registration.showNotification('Title', {'body': 'Body'});
});
When I send a message (I am using PHP-FCM BTW) the message gets received as expected in the browser when the page is under focus, through onMessage( ... ), but never when the page isn't under focus or the browser is closed; the service worker just doesn't receive the message!
The line "Received background message: ... " never shows; meaning that the message handler wasn't registered at all!
Here's a sample message response:
{
"from": " ... ",
"collapse_key": "do_not_collapse",
"data": {
"id": "111"
},
"priority": "high",
"notification": {
"title": "Hi there",
"body": "Message body",
"badge": "1",
"color": "#ffffff"
}
}
What could be the issue here? It's driving me crazy.
No it is registered but not invoked because of the way you choose to structure your notification. Referring to the FCM docs:
https://firebase.google.com/docs/cloud-messaging/js/receive
"Note: If you set notification fields in your HTTP or XMPP send request, those values take precedence over any values specified in the service worker."
So, you have
{
"from": " ... ",
"collapse_key": "do_not_collapse",
"data": {
"id": "111"
},
"priority": "high",
"notification": {
"title": "Hi there",
"body": "Message body",
"badge": "1",
"color": "#ffffff"
}
}
and this structure never triggers the BackgroundMessageHandler. Because sending data this way, simply overrides your variables. If you want to trigger it you need to send your notification like this:
{
"from": " ... ",
"collapse_key": "do_not_collapse",
"priority": "high",
"data": {
"id": "111",
"notification": {
"title": "Hi there",
"body": "Message body",
"badge": "1",
"color": "#ffffff"
}
},
"to": "topic",
}
I'm not sure that you can define the imports roots in the middle of your javascript, I think those calls need to be at the top.
Also the badge value and color are not supported by the FCM SDK. If you want to set the badge you can use the background message handler to show a notification use the normal APi and define the badge through that APi