Notification Message is not received to Android device from Azure Notification Hub - azure

I am using Microsoft azure notification hub for push notification in android. I am able to send notification through nodejs server code. Device get notification from nodejs server.
Problem :-
but when i use notification hub it the notification never comes through to the device even though the Notification Hub returns a success code.
Procedure I follow for notification hub.
Step -1 :- Register gcmTokenId to notification hub which i got from my device at a first time registration.
notificationHubService.gcm.createNativeRegistration(gcmToken, tags, function(error){
if(error)
{
res.type('application/json'); // set content-type
res.send(error); // send text response
}
else
{
res.type('application/json'); // set content-type
res.send('Registered Successfully!'); // send text response
}
});
Here are the registration details:-
{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj"
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}
Step -2 :- Send Notification to hub using following function.
notificationHubService.gcm.send(
null,
{
data: { message: 'Here is a message' }
},
function (error,response) {
if (!error) {
//message send successfully
res.type('application/json'); // set content-type
res.send(response);
}
});
Following are the response code i got from notification hub.
{
isSuccessful: true
statusCode: 201
body: ""
headers: {
transfer-encoding: "chunked"
content-type: "application/xml; charset=utf-8"
server: "Microsoft-HTTPAPI/2.0"
date: "Tue, 10 Jun 2014 07:07:32 GMT"
}-
}
Settings i did in notification hub:
I add google api key in "google cloud messaging settings".
Please guide me to solve this issue.

It appears that when you registered, you supplied "raj" as the tag.
{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj" <<== HERE
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}
A tag is like a subscription topic -- it is a filter.
You seem to be using the Node.js NotificationHubService.
Refer to http://dl.windowsazure.com/nodedocs/GcmService.html. The first parameter is tags, but in your code, you provided a null:
notificationHubService.gcm.send(
null, // <-- HERE
{
data: { message: 'Here is a message' }
},
Since null won't match the tag "raj", then Notification Hubs won't deliver this message to any device that is registered to listen only for messages that have the tag "raj".
You should either set the tag to "raj" in the send() method call, or remove that tag from the call to the createNativeRegistration() method.

Related

Error: Activity resulted into multiple skype activities bot FrameWork

I am trying to send an attachment using proactive messaging to a channel,
below is my code.
async function sendToChannelWithImage(message,channelId,img) {
MicrosoftAppCredentials.trustServiceUrl('');
var credentials = new MicrosoftAppCredentials('app-id', 'password');
var client = new ConnectorClient(credentials, { baseUri: 'https://smba.trafficmanager.net/us/' });
var conversationResponse = await client.conversations.createConversation({
bot: {
id: 'app-id',
name: 'test'
},
isGroup: true,
conversationType: "channel",
channelData: {
channel: { id: channelId }
},
activity: {
type: 'message',
text: message,
attachments: [img]
}
});
}
const img = {contentType: 'image/*',contentUrl: "https://theysaidso.com/img/qod/qod-inspire.jpg"};
message = 'test'
channelId = 'testid'
In this I am getting trying to send the message using bot framework,
what i have tried : https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-receive-attachments
Sending a proactive message to a Teams team channel is no different from sending a proactive message to a personal conversation, so you should be using sendToConversation instead of createConversation. To send a proactive message anywhere, you'll need to make sure you have the conversation ID. In Teams, it's also important to trust the service URL.
If you want to start a new thread in a team channel, you can do that by removing the thread ID from the conversation ID. See here: Microsoft Bot - Node SDK: How to post to a public channel *without replying to a prev. activity*
It looks like there's a sample about starting new threads in team channels if you'd like to check that out: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/58.teams-start-new-thread-in-channel

Dialogflow integration with Viber doesn't work with Rich Media type of message

I tried to use a custom payload to send the Carousel to the Viber client from my NODEJS fulfillment. It gives no response. Here is my code:
payload = new Payload(agent.VIBER, {
"type":"rich_media",
"rich_media":{
"Type":"rich_media",
"ButtonsGroupColumns":6,
"ButtonsGroupRows":7,
"BgColor":"#FFFFFF",
"Buttons":[
{
"Columns":6,
"Rows":3,
"ActionType":"open-url",
"ActionBody":"https://www.google.com",
"Image":"http://html-test:8080/myweb/guy/assets/imageRMsmall2.png"
},
{
"Columns":6,
"Rows":2,
"Text":"<font color=#323232><b>Headphones with Microphone, On-ear Wired earphones</b></font><font color=#777777><br>Sound Intone </font><font color=#6fc133>$17.99</font>",
"ActionType":"open-url",
"ActionBody":"https://www.google.com",
"TextSize":"medium",
"TextVAlign":"middle",
"TextHAlign":"left"
},
{
"Columns":6,
"Rows":1,
"ActionType":"reply",
"ActionBody":"https://www.google.com",
"Text":"<font color=#ffffff>Buy</font>",
"TextSize":"large",
"TextVAlign":"middle",
"TextHAlign":"middle",
"Image":"https://s14.postimg.org/4mmt4rw1t/Button.png"
},
{
"Columns":6,
"Rows":1,
"ActionType":"reply",
"ActionBody":"https://www.google.com",
"Text":"<font color=#8367db>MORE DETAILS</font>",
"TextSize":"small",
"TextVAlign":"middle",
"TextHAlign":"middle"
}
]
}
}, { sendAsMessage: true, rawPayload: false }
);
agent.add(payload);
The only workaround I found is to use a direct API call to Viber Messaging API from my Fulfillment. It explained well here: https://www.npmjs.com/package/messaging-api-viber
It seems it is a limitation of the Dialogflow at this moment. Just use workaround: a direct API call to Viber Messaging API from my Fulfillment. It explained well here: https://www.npmjs.com/package/messaging-api-viber

Firebase Cloud Messaging successful sendToDevice but no notification

I'm trying to write a cloud function which sends a push notification to an iOS device. The logs say that sendToDevice was successful. But my device isn't receiving any notifications. Neither Xcode nor Cloud Functions are showing any errors. How can I diagnose this problem?
My cloud function takes a registration token from the realtime database. This token is saved to the database during the didRegisterForRemoteNotificationsWithDeviceToken function in the ios app, confirming that the front end is registering for remote notifications. The app has been given permission to show notifications and the push notification capabilities have been enabled in Xcode.
This block of code comes from my cloud function (Node.js):
// This snapshot was taken from the realtime database
// Xcode logs confirmed that this function is receiving the correct key
const notificationKey = userSnapshot.child("notificationKey").val();
const payload = {
notification: {
title: 'Test Notification Title',
body: 'Test Notification Body',
sound: 'default',
badge: '1'
}
};
return admin.messaging().sendToDevice(notificationKey, payload).then(function (response) {
console.log("Successfully sent message: ", JSON.stringify(response));
return;
}).catch(function (error) {
console.log("Error sending message: ", error);
return;
});
When calling the cloud function above, the logs showed this console log (Id numbers truncated):
"Successfully sent message: {"results":[{"messageId":"0:154/* ... */"}],"canonicalRegistrationTokenCount":0,"failureCount":0,"successCount":1,"multicastId":576/* ... */}"
But my test device (iPhone 7) hasn't received any notifications. My app has the following delegate functions (Swift 4):
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
print("Notification will present: \(notification.request.content.userInfo)")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
print("Notification received: \(response.notification.request.content.userInfo)")
}
Neither print statement is appearing in Xcode's output. The only relevant print statements found are the ones I included in didRegisterForRemoteNotificationsWithDeviceToken. My APNs certificate is apparently still valid and has not expired.
The issue was simply that my podfile was missing:
pod 'Firebase/Messaging'
That allowed my didReceiveRemoteNotification to receive the notification payloads from Firebase cloud function. Then once I added UNUserNotificationCenter.current().delegate = self to the AppDelegate, the UNUserNotificationCenterDelegate functions worked as intended.
Strange how the missing pod didn't give me any compiler errors.

How to get the message sender UUID/metadata from pubnub history?

I want to know who sent the messages when retrieved from the pubnub.history!
pubnub.history() only returns timetoken and the message.
PubNub Sender UUID: realtime vs history
The sender (publisher) UUID is provided in the message you receive in realtime as a subscriber, but PubNub only stores the actual message you published along with any meta data that provided:
PubNub JavaScript SDK publish docs sample code
pubnub.publish(
{
channel: 'my_channel',
message: {
such: 'object'
},
meta: {
"cool": "meta"
}
},
function (status, response) {
if (status.error) {
// handle error
console.log(status)
} else {
console.log("message Published w/ timetoken", response.timetoken)
}
}
);
Best practice would be to add the publisher's UUID to the meta parameter which will not only allow you to get this value using history API, but you can also use it to filter out messages that the client has sent (don't receive your own messages using Stream Filter).

Send slack message as any username

I'm trying to create a new integration to combine slack with another chat system.
If someone sends a message from skype for example, I want his name to be used when the message is sent to slack. Right now I'm using IncomingWebhook to send messages.
private getWebClient(configuration: ConfigurationData): IncomingWebhook {
return new IncomingWebhook('https://hooks.slack.com/services/...');
}
const webhook = this.getWebClient(configuration);
await webhook.send(
{
text: 'How are you today?',
as_user: false,
username: 'slack_integration',
icon_emoji: ':chart_with_upwards_trend:',
thread_ts: event.ts
}
);
As you can see, I'm also trying to reply to the message in a thread. This is not working either. The following event I get looks as follows:
{ text: 'How are you today?',
bot_id: 'B9G8LHME1',
type: 'message',
subtype: 'bot_message',
ts: '1519830326.000061',
channel: 'C9G4BJ8BW',
event_ts: '1519830326.000061' }
The message still appears to be from my App. The name is "Slack Integration Test" (with a badge showing App right next to it).

Resources