How to send proactive notification/ broadcast message using Azure Functions to user using various channels?

871 Views Asked by At

I need to send proactive notification to the user that is scheduled at a certain time via Microsoft Bot V4. I am not exactly sure how to proceed with this.

Currently, I am trying to use Azure Function to send proactive message to user however, I'm not sure what to use to connect between bot service and azure functions. I looked at Direct Line but its not clear for me.

Currently, the best approach I can think of is to use Azure Function and Direct Line to send proactive notification to users.

I tested directline API via postman but it didn't work. It says conversational ID not found.

https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities

JSON POST

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "text": "hello"
}

After the message is sent it should give me the ID.

{
    "id": "0001"
}

Edit:

I managed to understand my issue with Direct Line. It doesn't allow me to send a message to DIFFERENT channel, like Web Chat or to bot on Skype. Is there any other option to send message to my user on Skype ?

2

There are 2 best solutions below

0
On BEST ANSWER

Okay so I sorted out my problem. By using REST connector https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-authentication?view=azure-bot-service-4.0 I think I just made big assumption that I have to use Direct Line

I maybe did not explain clear what my problem really was. Thanks for the replies !

1
On

You need to create output bot framework and Here is the binding information for the azure function which will be triggered after every x minute

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */1 * * * *"
    },
    {
      "type": "bot",
      "name": "$return",
      "botId": "Azurefunction",
      "secret": "AppSettingNameOfYourBot",
      "direction": "out"
    }
  ],
  "disabled": false
}

and the azure function is

using System; using System.Net; using System.Net.Http; using Microsoft.Azure.WebJobs.Host;

public class BotMessage { public string Source { get; set; } public string Message { get; set; } }

public static BotMessage  Run(TimerInfo myTimer ,TraceWriter log)
{
    BotMessage message = new BotMessage()
    {
        Source = "AzureFunction",
        Message = "Testing"
    };
    return message;
}

Also your binding configuration is set to use the return value of your function (also, in this case, that doesn't match any of the types supported by the binding) that's how you can make a connection between Bot and azure function.

And for directline api related issue please check this thread

Cant send message using directlineapi in bot framework

Hope it helps.