1

I was looking at the Proactive Notification sample on GitHub, and found out an api controller is used in order to send the notifications.

What I don't like about it is that it opens a browser tab/window which I don't need in my case.

I don't need to call any api either, I would prefer to call a method to acheive the same thing. So I build a similar controller from the samples but without being an api controller:

public class NotifyController
    {
        private readonly IBotFrameworkHttpAdapter _adapter;
        private readonly string _appId;
        private readonly ConcurrentDictionary<string, ConversationReference> _conversationReferences;
        private readonly GretaDBContext DBContext;

        public NotifyController(IBotFrameworkHttpAdapter adapter, ConcurrentDictionary<string,ConversationReference> references,
            GretaDBContext dbContext, IConfiguration configuration)
        {
            _adapter = adapter;
            _conversationReferences = references;
            DBContext = dbContext;
            _appId = configuration["MicrosoftAppId"];

            if (string.IsNullOrEmpty(_appId))
            {
                _appId = Guid.NewGuid().ToString(); //if no AppId, use a random Guid
            }
        }

        public async Task NotifyValidation(int id)
        {
            foreach(var conversationReference in _conversationReferences.Values)
            {
                //METHOD LOGIC FOR SENDING PROACTIVE NOTIFICATION
            }
        }
    }

My intention is injecting this to my Dialogs and call one of the public functions in order to notify some users that their profile has been validated.

I have a couple questions:

  1. Would be better to use an api like the samples do and avoid opening the browser in some way? Or is injecting this controller to the Dialogs a good solution too?

  2. In case the answer is injecting the non api controller, do I declare it as a scoped, singleton or transient service?

1 Answers1

1

There's definitely another way to do this - you can create a ConversationContext in a separate application, based on, say, a message queue of some sort, and send the proactive messages inside that application. I've got, for instance, an Azure Function that sends pro-active messages to specific users on a specific schedule. To do this, you do need to have certain information, in particular a conversation id, serviceurl, and so on, which you need to get and store beforehand. There are multiple ways to get this info, but the easiest is if you have a conversation existing between your bot and the user(s) in question.

I'm happy to help more, but please read my other answer on this topic here, as it might be what you need: Programmatically sending a message to a bot in Microsoft Teams

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24