With https://portal.azure.com I managed to create a QnA Bot.
I also managed to send a message from the Bot Framework Emulator to MS Teams and the Test Web Chat of the bot. (Though it is very static and manually done as of now)
I get my Token from https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token. With that Token I can send a message to https://smba.trafficmanager.net/emea/v3/conversations/ConversationID/activities (which is Teams) and I can send a message to https://webchat.botframework.com/v3/conversations/ConversationID/activities (which is the Test Web Chat).
Little bit offtopic: Since I'm new to Azure I wonder if everything done so far is fine or completly false?
Anyway...
My goal so far is that when writing a message in the Test Web Chat the message should also end up in MS Teams. Then from Teams I want to answer to the message like #Bot This is my Answer. This Answer in Teams should then also end up in the Test Web Chat. (So basically communication between Teams and Web Chat)
What would be the best approach to do this?
I was thinking of a backend in Azure but I don't know what would be possible to use and if it's even possible.
My idea was:
A message is sent Web Chat. In Code I would upload the Web Chat Conversation Information to Azure. Also in Teams there is now the same message that was written in Web Chat. The Conversation ID in Teams also needs to be uploaded now and the Conversation ID the Web Chat is sending to needs to be updated (this would be needed so there is no spamming of new threads/messages in Teams from one Conversation and all the messages from this Web Chat Conversation are now in one thread.) Now to answer in the Conversation of the Web Chat via Teams I would write and send the answer. Before the sending of the answer happens I would need the Conversation ID from the Web Chat. So the Bot would download the information from Azure so it knows where it has to sent the answer to.
Is this a good apporach or do you know better ones? Also what ressources in Azure could I use to achieve this?
It sounds like you are thinking about this the right way. Basically you want to pair two conversation references - one in Teams and the other in Web Chat - together and then forward the messages between the two.
BotFramework SDK v4 (C#)
I would recommend creating two functions - AddConversationReferenceAsync and GetConversationReferenceAsync. In those functions, you should manage how you store, connect, and retrieve conversation references. You can check the channel Id - activity.ChannelId - to determine how you want to handle the reference. Then in OnMessageActivityAsync you can add and retrieve the corresponding conversation references to send a proactive message to the other channel.
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
AddConversationReferenceAsync(turnContext.Activity as Activity);
var conversationReference = GetConversationReferenceAsync(turnContext.Activity as Activity);
if (conversationReference != null) {
await turnContext.Adapter.ContinueConversationAsync(_appId, conversationReference, (ITurnContext context, CancellationToken cancellationToken) => {
await context.SendActivityAsync(turnContext.Activity);
}, cancellationToken);
} else {
await turnContext.SendActivityAsync("You are not connected to anyone at the moment");
}
}
Screen Capture
I would recommend looking at the BotBuilder Proactive Messaging sample, and #tompaana built a Hunan Handoff Bot sample that connects conversations in Teams and Slack that might be helpful.
Hope this helps!
Related
I have a messaging extension that will be used with our VoIP system.
Let's say I have a 1:1 conversation with another user. I want my messaging extension to be able to fetch the other user's information (Name, email, AadObjectId, etc). The closest information I get is the Conversation ID of the 1:1 chat with that user. I then tried both the following:
SDK:
List<ChannelAccount> teamMembers = (await turnContext.TurnState.Get<IConnectorClient>().Conversations.GetConversationMembersAsync(turnContext.Activity.Conversation.Id).ConfigureAwait(false)).ToList();
As well as the direct endpoint with the conversation id:
https://smba.trafficmanager.net/amer/v3/conversations/{REDACTEDCONVERSATIONID}/members
Both gave me error 403 (Forbidden) with the message:
"error": {
"code": "BotNotInConversationRoster",
"message": "The bot is not part of the conversation roster."
}
We really need the messaging extension to be able to pull that information out, is there any way we can do so?
I am using the BotFramework SDK, latest version
So as you've discovered, you can't do this the way you're trying to, via the bot directly (i.e. via the 'conversations' endpoints) if the bot is not actually installed into that particular location (1-1 chat, channel, etc.). However, this definitely -is- possible, just via another route. What you need to do is to use Microsoft Graph, in particular the operations to get conversation members. However, in order to do this, you'll need to implement sign in in your Message Extension. Fortunately, there was a discussion on this exact topic in the latest Teams community call from this month. The sample is in node, but the same applies to C# (what I see you're using).
I created bot using QnaMaker.ai service and Microsoft azure services.It's working fine with webchat channel.Now i integrated it with Microsoft Team channel and that's where i got into a problem.
The prompts that were working in webchat channel are not working same in Teams channel.
Like for question i showed 4 options to select.But in microsoft teams they are Bot in webchat channel
and bot in Teams
Are you trying to show Suggested Actions? Suggested actions are not supported in Microsoft Teams. if you want buttons to appear on a Teams bot message, please try using cards.
You can use ChoiceFactory.toChoices in Teams and it will work. I prefer this method because it's simple (all you need is the array of choices as strings) and it works, but you can also use ChoiceFactory.forChannel which should automatically format the choices for ANY channel. Here is an example from one of the bots I use in Teams, where the buttons display fine. This is nodejs but the same class will work in C#.
FOCUS_AREAS = ['Chatbots','RPA','Blockchain','AR/VR','AI & ML'];
return await step.prompt(FOCUS_AREA_PROMPT, {
prompt: 'Which focus area is this for?',
choices: ChoiceFactory.toChoices(FOCUS_AREAS)
});
Reference from Microsoft: https://learn.microsoft.com/en-us/javascript/api/botbuilder-dialogs/choicefactory?view=botbuilder-ts-latest
Examples:
Here is the output from the code above. The total length is too long to render as buttons in Teams channel, so it has automatically switched to a numbered list.
The below uses the same exact ChoiceFactory.toChoices implementation, just with fewer options so it renders as buttons instead of a numbered list.
I've built a small basic web bot app using bot framework and want to deploy it on Azure. I've followed all the steps and it's working fine under "Test in Web Chat" of Azure Portal too, but however as I open my bot's endpoint
https://optlbot.azurewebsites.net/api/messages
I get an error saying
The requested resource does not support http method 'GET'
Can somebody please help me, I can't debug my application at all. I've also tested on emulator and there too it's working fine.
Yes, the URL https://optlbot.azurewebsites.net/api/messages works only for POST request and not a GET request, because you post a message from user to bot and not a get, you can see that in the MessagesController code.
Being said that, if you want to test your bot locally, you have to use the emulator. You can have a look at Bot emulator for the same.
Now if you want to publish the bot to the world so that others can see it and use it, so that's where the channel comes in. Consider channel as a medium by which you enable your bot for others to use with a much better user experience.
There are multiple channels available for the bot to be published in, and yes you can publish the same bot in all the channels.webchat is just one channel and the one which is enabled by default and the way to see it is :
Open your bot in the Azure Portal and click Channels blade.
Click Edit for the Web Chat channel
Under Secret keys, click Show for the first key
Copy the Secret key and the Embed code.
Click Done
So the embed code is actually an iframe which you can place in your website or share with others who want to use your bot. Or you can use the src of the iFrame too to reach the bot directly.
Again this is just one channel. You can take a look at the Configure channels documentation for steps to enable the bot in more channels like Skype, Microsoft Teams, Email, Facebook, Slack, Telegram, etc.
If you check the code of your MessagesController, you would find the following action defined in your controller, it only accept POST request and read the value of activity from the request body, it does not support http method 'GET'.
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
I have got a requirement,
When a work item is created (and status -say In progress) in TFS 2015(not vsts), I want my web hook to fire a post method which ll create a Channel in Slack, and invite few folks.
2) Once the Bug is closed - read all the history of channel and push the history back to Bug.
I was able to achieve the same with TFS server side plugin and it's working, but requirement got changed to Web hooks.
Could someone help me on how to achieve custom web hook.which ll enable events from TFS WI to Slack please?
Thanks,
You can not create new incoming webhooks in slack programmatically, but you can use any existing incoming webhook for a new channel.
Just add the channel property in your message to the webhook.
Example from the Slack documentation:
curl -X POST \
--data-urlencode 'payload={"text": "This is posted to #general and comes from *monkey-bot*.", "channel": "#general", "link_names": 1, "username": "monkey-bot", "icon_emoji": ":monkey_face:"}' \
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
So to implement your requirement I suggest you create a new channel and invite users as needed through the Slack web API. And then use an existing incoming webhook to send messages to that channel.
TFS has default slack service hook which can post a message to a channel. The API looks like below:
POST http://tfsserver:8080/tfs/DefaultCollection/_apis/hooks/subscriptions?api-version=3.2
Content-Type: application/json
{
"consumerActionId":"postMessageToChannel",
"consumerId":"slack",
"consumerInputs":{
"url":"https://hooks.slack.com/services/xxxxxx"},
"eventType":"workitem.created",
"publisherId":"tfs",
"publisherInputs":{
"areaPath":"",
"workItemType":"",
"projectId":"77e3c775-dc30-4354-xxxx-xxxxxxxxxxxx"}
}
For your second requirement, you need to check Slack Api to see how to read all the history of channel, and use Update work items to update Bug work items.
Here i called the method into my SignalR Hub Class to brodcast messages to user.i did another method for to send messages to all connected users but now i want to sendand receive messages between two user
Create groups
Add a client to a group:
Groups.AddAsync("YourGroupId", Context.ConnectionId);
Remove client from group:
Groups.RemoveAsync("YourGroupId", Context.ConnectionId);
Send message to a group:
Clients.Group("").MethodOnYourClient("");
Remark:
I suggest you to read the tutorial: https://learn.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr
I know it's not with asp.net core signalr, but the most of the stuff looks similar. Maybe you have to show in intellisense which possibilities the existing classes have.