Prompts not showing in in microsoft Teams integrated bot - c#

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.

Related

Fetching user information on Messaging Extension (Microsoft Teams)

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).

How to create a Message (Email) Object and mark it as "Sent" without sending it with Microsoft Graph API? C# and/or Java Graph SDK

I am looking for a way to create an email object in Outlook using the Microsoft Graph Api and to mark the object as "Sent" so it does not show up in outlook as a draft.
I have done the following:
Mark the item's property "isDraft" to be false,
Upload the item directly into the sentMail Mailbox
give the item a valid sentTime in the past
Every combination of the above three.
No matter what i do, when i navigate to outlook mail, the email shows up as a draft in my mailbox.
Answer is located at Microsoft Graph API mail office 365: Is any option create inbox message NOT as Draft?
It should be noted that for those using the Graph SDK you must use the built in properties and objects to set the options listed in the above link. Its the first answer that has the value: "4" attached to it that worked for my specific problem.
Data type in question for C# graph SDK -> https://learn.microsoft.com/en-us/graph/api/resources/singlevaluelegacyextendedproperty?view=graph-rest-1.0

How to display HTML table inside a chat window with options & buttons in it using Microsoft BOT Framework V4 template using C#?

How to display HTML table inside a chat window with options and buttons inside it in a web chat bot created through Microsoft BOT Framework using C#?
I am developing a Chat Bot using waterfall dialog having multiple dialog classes where each class does a specific task based upon the option selected in the web chat Window.
What i need is to display a table in web chat bot window such that is displays a a HTML table with TH's,TD's and TR's and each row with specific button in one of its columns in each row such that the button when clicked dies the specific action?
Is this can be done? or is it a wrong expectation?
If this can be done, is using Adaptive Cards is only the Option or we can actually display a HTML table created inside the C# program inside a stream writer displayed directly into the web Chat Bot?
Please help in this issue as detailed as possible in a step by step detailed guide manner as i am new to C# coding and BOT.
The bot is build using:
Language: C#
SDK : V4 template
Framework: Microsoft Bot Framework
When searched got the answer as to do using Adaptive cards using column set options wanted to know if we can do it by actually directly constructing a HTML content inside a stream and display the table in the WebChat Bot.
By default, Web Chat uses the markdown-it npm package to render incoming activities. The default renderer isn't configured to handle HTML so you won't be able to send an HTML table in activity out of the box; however, you can implement your own markdown renderer that supports HTML and pass it as a prop to Web Chat.
const markdownIt = new MarkdownIt({ html: true, linkify: true, typographer: true });
const renderMarkdown = text => markdownIt.render(text);
...
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
renderMarkdown
}, document.getElementById('webchat'));
For more details, take a look at this issue on GitHub in the Web Chat Repo.

Communication between Teams and Web Chat via Bot

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!

What are the available functions to send notifications to a Facebook user?

Currently I am using Codeplex's Facebook Developer Toolkit version 2 for my ASP.net Facebook application. I would like to be able to send notifications to a user's Inbox or wall of the application and was wondering what are the available functions to do that? If not in the API, then please provide example functions from the main Facebook library. This will help immensely. Thanks!
After a brief search I found an example of sending notifications using the toolkit:
facebook.Components.FacebookService fs
= new facebook.Components.FacebookService();
fs.ApplicationKey =
ConfigurationManager.AppSettings["APIKey"];
fs.Secret =
ConfigurationManager.AppSettings["Secret"];
string sessionKey =
dict["facebook_session_key"];
fs.SessionKey = sessionKey; fs.uid =
long.Parse(member.FacebookId);
fs.notifications.send(member.FacebookId,
"notification message");
(from: http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=49876)
After looking through the Codeplex source it's clear that this sends a user-to-user notification, and therefore requires an active user session of the sender.
Codeplex does not appear to support app-to-user notifications which do not require a session, but adding this feature would be trivial. Add a type variable to the send method and set it accordingly based on the API documentation here: http://wiki.developers.facebook.com/index.php/Notifications.send
The source code for the notifications.send method in the Codeplex Developer Toolkit is here:
http://facebooktoolkit.codeplex.com/SourceControl/changeset/view/28656#233852
Please keep in mind that the Codeplex developer toolkit source code has not been updated in over 3 months. This means that it does not support many new Facebook API features and changes. You may want to browse the client library wiki page to find a library that is more up to date: http://wiki.developers.facebook.com/index.php/Client_Libraries

Categories