Error when enabling diagnostic logs - Azure Botframework - node.js

I'm having a problem where my Bot Framework bot stops responding to Kik.
I'd like to enable the diagnostic logs in Azure, but when I click "save", I get the error message "Failed to update web app logs settings for autoCompeteBot. There was an error processing your request. Please try again in a few moments."
Any idea how I can avoid this error and see my logs?
Thanks!

I followed the answer by #hailiu2586 here: https://github.com/Microsoft/BotBuilder/issues/1909.
Replace the following line in your messages/index.js
module.exports = { default: connector.listen() }
With:
var listener = connector.listen();
var withLogging = function(context, req) {
console.log = context.log;
listener(context, req);
}
module.exports = { default: withLogging }
After that done, console.log() should work.

Related

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.

An error occurred creating push for user scripts: azure.notificationHubService could not be created

In Azure Mobile Service javascript backend ,trying to send a notification by calling notification hub through custom api. Its giving me a notification , but everytime giving a time out error too. I observed my logs and its showing "An error occurred creating push for user scripts: azure.notificationHubService could not be created" .
Instead of using azure.createNotificationHubService method , is there any way to import already created notification hub service ?How to get rid of the time out error. I am pasting function below.
function sendnotification() {
var azure = require('azure');
var notificationHubService = azure.createNotificationHubService('disapphub','Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=my_key_here=;');
var payload = {
data: {
"type":"newthread",
}
};
var mytags ='admin';
notificationHubService.gcm.send(mytags, payload, function(error){
if(!error){
//notification sent
}
});
}

Notification Hub RegistrationAuthorizationException

I followed this link yesterday to receive notification from azure notification hub on my windows 8.1 phone app and it was working but
But today it is throwing me this error
An exception of type 'Microsoft.WindowsAzure.Messaging.RegistrationAuthorizationException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: HTTP request failed.
HTTP Details:
Status: 401
Reason: Unauthorized
Full content: <Error><Code>401</Code><Detail>ExpiredToken: .TrackingId:e27f22fb-5c9c-4028-8594-eacb71e5a35e_G1,TimeStamp:4/14/2016 10:29:33 AM</Detail></Error>
It is throwing this exception in the InitNotificationsAsync method in my App.xaml.cs when my app is trying to register
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("nameofhub", "myconnectionstring");
var result = await hub.RegisterNativeAsync(channel.Uri);
//Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
Do you try it in the emulator or..?
It can be the time syncronization.
If that is the emulator, can you check the time and set it up manually?

Push notification for toast not working in azure

My Push notification code for toast notification is not running when run through scheduler in azure. my code is
function EWSReminder() {
push.wns.sendToastText01("https://sin.notify.windows.com/? token=Ysdfdhjkdjksj%2fAScjFHiwrUbS6y%2bvumj9sKUqhklsdfjgfdslcvl;dklslkskdlsdl;9XD58CMJebd04EknQY0Hgaxed6%uirutiuritubW%2fRcpdvapAYlMcnWLE360%3d", {
text1: "Sample toast from sample insert"
}, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse);
}
);
}
I get this error
Error in script '/scheduler/EWSReminder.js'. Error: The options.client_id and options.client_secret must be specified as strings or the WNS_CLIENT_ID and WNS_CLIENT_ID environment variables must be set.
[external code]
at EWSReminder (</scheduler/EWSReminder.js>:2:16)
at </scheduler/EWSReminder.js>:1:13
[external code]
I can't figure out what the problem is pls help. I have applied code of all the microsoft samples available all have the same code, but none is working for me.
You need to set Client Secret and Package SID in Azure Portal (Push tab in your Mobile Service). These credentials can be obtained through Windows Store Developer Portal.
Even I too have the same issue and I have put the values in the portal which I took from the Windows Store Developer Portal.
The below code works for me but the above code doesn't as shown by Yesh.
var pushWNS = require('wns');
pushWNS.sendToastText01(uri, { text1: Name }, { client_id: 'xxx', client_secret: 'xxx' },
function (error, response)
{
if (!error)
{
// success code
}
else
{
// error handling
}
});
and also I wanted to know the difference between both the codes mentioned by me and Yesh

Not able to add entities to a azure storage table in node.js when deployed to cloud?

I am using socket.io in node.js to implement chat functionality in my azure cloud project. In it i have been adding the user chat history to tables using node.js. It works fine when i run it on my local emulator, but strangely when i deploy to my azure cloud it doesnt work and it doesnt throw up any error either so its really mind boggling. Below is my code.
var app = require('express')()
, server = require('http').createServer(app)
, sio = require('socket.io')
, redis = require('redis');
var client = redis.createClient();
var io = sio.listen(server,{origins: '*:*'});
io.set("store", new sio.RedisStore);
process.env.AZURE_STORAGE_ACCOUNT = "account";
process.env.AZURE_STORAGE_ACCESS_KEY = "key";
var azure = require('azure');
var chatTableService = azure.createTableService();
createTable("ChatUser");
server.listen(4002);
socket.on('privateChat', function (data) {
var receiver = data.Receiver;
console.log(data.Username);
var chatGUID1 = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
var chatRecord1 = {
PartitionKey: data.Receiver,
RowKey: data.Username,
ChatID: chatGUID2,
Username: data.Receiver,
ChattedWithUsername: data.Username,
Timestamp: new Date(new Date().getTime())
};
console.log(chatRecord1.Timestamp);
queryEntity(chatRecord1);
}
function queryEntity(record1) {
chatTableService.queryEntity('ChatUser'
, record1.PartitionKey
, record1.RowKey
, function (error, entity) {
if (!error) {
console.log("Entity already exists")
}
else {
insertEntity(record1);
}
})
}
function insertEntity(record) {
chatTableService.insertEntity('ChatUser', record, function (error) {
if (!error) {
console.log("Entity inserted");
}
});
}
Its working on my local emulator but not on cloud and I came across a reading that DateTime variable of an entity should not be null when creating a record on cloud table. But am pretty sure the way am passing timestamp is fine, it is right? any other ideas why it might be working on local but not on cloud?
EDIT:
I hav also been getting this error when am running the socket.io server, but in spite of this error the socket.io functionality is working fine so i didnt bother to care about it. I have no idea what the error means in the first place.
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
Couple things:
You shouldn't need to set Timestamp, the service should be populating that automatically when you insert a record.
When running it locally you can set the environment variables to the Windows Azure storage account settings and see if it will successfully write to the table when running on your developer box. Instead of running in the emulator, just set the environment variables and run the app directly with node.exe.
Are you running in a web role or worker role? I'm assuming it's a cloud service since you mentioned the emulator. If it's a worker role, maybe add some instrumentation to log to file to assist in debugging. If it's a web role you can add an iisnode.yml file in the root of the application, with the following line in the file to enable logging of stdout/stderr:
loggingEnabled: true
This will capture stdout/stderr to an iislog folder under the approot folder on e: or f: of the web role instance. You can remote desktop to the instance and look at the logs to see if the logs you have for successful insertion are occurring.
Otherwise, it's not obvious from the code above what's going on. Similar code worked fine for me. Relevant bits for my test code can be found at https://gist.github.com/Blackmist/5326756.
Hope this helps.

Resources