Fetching user information on Messaging Extension (Microsoft Teams) - c#

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

Related

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

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!

How to receive attachments from a user with Bot Framework in C#?

I am developing a bot in C# with Bot Framework and I would like to obtain the attachments sent by the users.
They seem to be in a location similar to this one:
ContentType: audio
ContentURL: https://smba.trafficmanager.net/apis/v3/attachments/0-weu-d9-734cab9e78c28a1619a39ce8c69342d1/views/original
Name: 2-audioMessage.m4a
When I do a get request it shows me the following:
{"message":"Authorization has been denied for this request."}
How can I get the attachments? (in my case they are voice notes in Skype).
Thanks.
you get the attachments from activity instance in turnContext object, you can add your custom code to save it in specific location like azure storage or sharepoint library

How to fetch the messaging of linkedin user

I wanted to fetch the messages that was sent to the other connected linkedin users.
I found a code sample to send the message in this site
https://developer.linkedin.com/documents/sample-code-sending-message
But, I did not any sample to fetch the messages.
However, when I tried to fetch the message with the query "/people/~/mailbox", I got the error
"The remote server returned an error: (403) Forbidden."
In detail error message, I got "Access to mailbox denied".
These 2 documentations has listed only the Primary Endpoints "POST /people/~/mailbox" but has not mentioned about GET.
https://developer.linkedin.com/oauth-10a-overview
https://developer.linkedin.com/documents/authentication#oauth2-redirect-uri
Is there any way to fetch the message? Or Is there any workaround?
Any insights or help will be highly appreciated.
Thanks
I don't think Linkedin Inbox is supported any longer through their API. As per this answer on quora,
API is not publicly available but has been made available to several
partners. The best thing to do is contact LinkedIn's BD team for
access.
I was not able to see any specific mention to this type of access in their documentation.
Furthermore, check out APIGEE Snapshot for LinkedIn's 3 main API categories

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