response to conversationUpdate on Skype for Business - botframework

I intend to send a greeting message from the bot on Skype for Business when the user initially opens the chat window. To achieve this I'm trying to respond to the conversationUpdate event from the bot. When I respond to the conversationUpdate event, i receive the following error that conversation does not exits
{"Error":{"Code":"ServiceError","Message":"Conversation does not
exist"}}
But when the same user sends a message, I receive the message with the same conversationId and am able to respond back without any issues.
I'm able to do this without any issues on the web chat but not on SfB. I looked at some issues on Microsoft's GitHub repository for the bot, which suggested that the question may be best answered on SO.
Updates
I was earlier on SfB 2013. I've upgraded to SfB 2016 and the bot responds to the conversationUpdate event it receives once the user sends his first message. Usually on a web chat, the response to the first conversationUpdate is sent as soon as the user opens the window and a second response is sent once the user sends his first message. In the case of SfB, the response to second conversationUpdate is working but not for the first conversationUpdate.
Web Chat
Skype for Business
As explained above, the response to first conversationUpdate will result in the
Conversation does not exist
error. The response to the second conversationUpdate when user sends his first message works.
So now how do we make the welcome message work for the first conversationUpdate and disable it for the second conversationUpdate update ?

I am not sure, why converstaionUpdate event didn't triggered. But as mentioned in BotFramework docs, not every channels supports that event. You can add a first run dialog instead and check if that works. Adding a sample from the docs page:
// Add first run dialog
bot.dialog('firstRun', function (session) {
session.userData.firstRun = true;
session.send("Hello...").endDialog();
}).triggerAction({
onFindAction: function (context, callback) {
// Only trigger if we've never seen user before
if (!context.userData.firstRun) {
// Return a score of 1.1 to ensure the first run dialog wins
callback(null, 1.1);
} else {
callback(null, 0.0);
}
}
});

Related

Webex AttachementActionData usage

How is this class used? If there is a submit button using Action.Submit on an adaptive card, how does the Microsoft Bot get this message?
So this question doesn't get flagged as too generic, there is a Webex adapter connected to a Microsoft bot using this exact demo.
https://learn.microsoft.com/en-us/azure/bot-service/bot-service-adapter-connect-webex?view=azure-bot-service-4.0
The OnMessageActivityAsync message gets the message from the bot, for example, if the user types "Hello", and the bot responds back with an adaptive card that has the action "Action.Submit" that will give the user a card with a submit button. Now, if the user clicks "submit", Webex should send something back to the bot. I don't think it's a message, because I never receive a message. Webex has, on it's side of documentation, a webhook with ActionAttachments. But after creating this webhook and clicking submit, what is the bot supposed to receive?
The answer to this was to change the Webex access token from the auto-generated token to the bot's access token. After doing this, the Action Attachment was working and the bot received the Event Activity.

Slack event message.im not being triggered

I'm trying to get the event to be triggered when someone sends a message on a private conversation in slack, I've already registered the event subscription (message.im) in the subscribe to bot events section, made sure that the needed scope was added (im:history), and reinstalled the app on my workspace.
Also tried signing out of the workspace and logging in again.
Yet, even if it is the admin sending a message to a user or a user sending a message to the admin (or in any other case with other users) the Event is not being triggered.
Any help or suggestion of why could this be happening?
Thanks!
You receive this event when a user sends a direct message to your bot/app.
You wouldn't receive this event when a user sends a message to another user, because the bot is not a part of that conversation.

Use ContinueDialogAsync in ProActive message after ending dialog turn

I am trying to 'pause' a bot conversation and resume it via a ProActive Message.
The way I have been trying to do so is by ending the dialog turn to 'pause' the conversation. Following I'm using ContinueDialogAsync in my ProActive message to 'resume' the conversation. Below is how I'm doing this as part of the ProActive message:
DialogManager dialogManager = new DialogManager(this.resourceExplorer.LoadType<AdaptiveDialog>(this.resourceExplorer.GetResource("echobot-final.dialog")));
dialogManager.UseResourceExplorer(this.resourceExplorer);
dialogManager.UseLanguageGeneration();
var conversationStateAccessors = conversationState.CreateProperty<DialogState>(nameof(DialogState));
var dialogSet = new DialogSet(conversationStateAccessors);
dialogSet.Add(dialogManager.RootDialog);
var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
However, when running the ContinueDialogAsync after the dialog turn had been ended previously, I run into this error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Bot.Builder.Dialogs.Adaptive
StackTrace:
at Microsoft.Bot.Builder.Dialogs.Adaptive.Generators.ResourceMultiLanguageGenerator.TryGetGenerator(DialogContext dialogContext, String locale, LanguageGenerator& languageGenerator)
I'm not getting this NullReferenceException though when removing the EndTurn from the dialog, so I believe I my dialogContext object should be correct?
Am I misunderstanding the concept of ending a dialog turn?
What is the correct approach to pause a conversation, and resume the conversation later?
In the Bot Framework, a turn is the time between the bot receiving an activity in an HTTP request and the bot responding to that request. Note that responding to an HTTP request is different from replying to an activity. The bot can reply by sending new activities to ABS in their own HTTP requests, and it can do this many times in a turn. The HTTP response is not another activity, it's just a status code (like 200 OK) that signifies the end of the turn.
There's not really a concept of a "dialog turn." There are "steps" in waterfall dialogs and adaptive dialogs, though they don't correlate to turns since a step can span multiple turns and a turn can span multiple steps. There is an "End Dialog Turn" action in adaptive dialogs which I think is what you're talking about, but it just ends the turn. The word "Dialog" may be superfluous/misleading there.
There also isn't really a concept of "pausing" a conversation. A conversation is understood to be a series of turns and activities exchanged between a bot and one or more users. Your bot always needs to know what to do about every request that reaches its endpoint, so it's up to you to define what pausing a conversation means.
I'm guessing you want the bot to respond differently or not respond at all while the conversation is paused. You will need some sort of bot state for the bot to know that it's paused for a given user or conversation, and dialogs use bot state so a dialog would do. Whatever you do to indicate to the bot that the conversation is paused, you can just undo it to unpause it. Just ending the turn won't work because that doesn't add anything to state and the next turn will start as soon as the user sends a message.

How to get a welcome message on teams even before user sends any message

I have deployed my bot on teams channel.
I would like to send a welcome message to a new user even before user sends a message to the bot.
can we achieve this for teams channel?
If yes, which event can be used to get that user is accessing bot for the first time.
You can use the ConversationUpdate event ActivityTypes.ConversationUpdate // in c#
When a bot is installed, your bot receives a conversationUpdate event. You can then send a proactive message to the user. Could you please try sending a proactive message and let us know if you face any issues?
The conversationUpdate event with the membersAdded object in the payload is sent when either a bot is added to a team or a new user is added to a team where a bot has been added. It is always a good practice to send a welcome message introducing the bot to all the users. Ensure that your bot responds to the conversationUpdate message, with the teamsAddMembers eventType in the channelData object. Also, keep in mind that the memberAdded ID is the bot's App ID itself, because the same event is sent when a user is added to a team.
Hope this helps.

Proactive Interruptions

I am using an Azure Function to send a Proactive message to the client. How do i "reset" a conversation when a Proactive message is sent.
Within the bot, a user might be prompted for something (ex. time of day). A proactive message may get sent to them before they respond. In this scenario, I would like to reset/cancel the previous dialog and start fresh.
I am already able to reset the dialog using CancelAllDialogsAsync which works fine for user-driven messages.
I am sending my proactive message using ConnectorClient, which bypasses the framework, and sends directly to the client, thus never hitting my middleware to reset the dialog.
How can I get the proactive message sent to the framework (i can send the response from the bot no problem)
I would highly recommend you solve this by having your function send your bot a backchannel event under the context of the ConversationReference via the ConnectorClient. This way the bot maintains ownership for all the details about state and what should happen when this event occurs rather than that responsibility leaking to the function. The bot then watches for this custom event and responds to it however it sees fit.
If you need any more details let me know and I'll update my answer.

Resources