Posts

Generate "session" object using bot.loadSession()

I need to send a reminder message within a function which outside "bot.dialog()". This function is triggered by a HTTP post event and so no "session" parameter will be passed in. I want to create a "HeroCard" message which needs "session" object. I search around in google and then found out the solution which is using "bot.loadSession()". You need to pass in the message address (session.message.address) to this function. The sample code is as below: var msg = new builder.Message().address(address); bot.loadSession(address, (error, session) => {  msg.attachments([  new builder.HeroCard(session)  .title(title)  .text("XXXXX")  .images([builder.CardImage.create(session, "imageURL")])  .buttons([ builder.CardAction.openUrl(session, "actionURL", "XXXX") ]) ]);  session.send(msg); });

Azure Bot Framework: using URL to send poactivate message (Node.js)

Firstly create a chatbot using Azure Bot framework and then deploy to github and web app (Refer to this article https://github.com/fuselabs/echobot ). Using the function to send poactivate message based on this sample https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/core-proactiveMessages/simpleSendMessage/index.js Note: the function "sendProactiveMessage" must placed before the "server.get"code.  function sendProactiveMessage(address) {   var msg = new builder.Message().address(address);   msg.text('Hello, this is a notification triggered by url');   msg.textLocale('en-US');   bot.send(msg); } server.get('/api/custom', function(req, res, next) {   sendProactiveMessage(savedAddress);   res.send('home: ')   return next(); });  Before using above web app,  I used the Azure bot service to create a bot and then modified the code to add poactivate function. However, it didn't work and so I changed to use Azure...

T-SQL: Conver null or empty string to numeric value

I tried to use sum for a "varchar" type column in SQL table, and one day the code has error as there is a line contains empty value in this column and so the sum() function not working anymore. So I add following function NULLIF (<clumn>,0) The whole sum function is as below: sum(CAST(NULLIF(AMOUNT,0) AS DECIMAL(22,2))) Now I can get the sum amount value successfully.

Node.js - Get return value from call back function with Azure Bot Framework

I have been started to built a chatbot using node.js within Azure Bot Framework. I need to get return value from a HTTP request's response result. I was using the "normal" way of function (callback){} in node.s, but no luck to get the return result. I did a research and then found out this article " Microsoft Bot Framework Node SDK and LUIS ". Refer to this article, I finally work out the way of getting return value as below. var rp = require('request'); bot.dialog('SearchHotels', [  function (session) {    var destinationUrl="XXXX";   callRemoteSite(destinationUrl, (responseString) => {             session.send(responseString);      }); } function searchHotels(destinationUrl, callback) {  rp(destinationUrl, function(error, response, body) {           var json= parseFinance(body);          callback(json);   }) } The advantage of above function is you can...

Registered Tags are droped by Azure Push notification hub

I have been met a strange issue that the registered Tags are dropped by Push Notification hub in some time after registered successfully in Azure. I use the installation mode to register Tags via a controller function in Mobile App back-end service. I can see those tags are added to the hub via the server explorer within Visual Studio. After few days, I run the app again and unable to receive the push notification message target to those tags anymore, and so I went to the server explorer and found those tags are gone!   After investigation, I found the issue was caused by following code: // Register the channel URI with Notification Hubs.  await App.MobileService.GetPush().RegisterAsync(channel.Uri);  As I didn't provide the template contains tags, and so the register function remove those tags from the hub. After remove above the line, the app can receive message consistently and those tags are there forever now. However, if I run above code after regi...

Enable scheduled push notification in Azure

The scheduled feature of Push notification hub in Azure is not available in "Free" and "Basic" pricing tier, and so if you need to send scheduled push notification message, then choose "Standard" pricing tier.