RocketChat API - Impersonate users for getting the list of unread messages of each one - rocket.chat

Hi, all.
I need to retrieve the list of unread channel messages for each user in order to create a graph for internal use in my company. Looks like there is no "impersonate" feature available via the API. Gitlab says this discussion will be moved to the forum, and the forum redirects to Gitlab. Dead end.
var client = new RocketChatClient(url, "admin", password);
var bobMessages = client.sendAs("bob").getMessagesApi().list();
var johnMessages = client.sendAs("john").getMessagesApi().list();
var janeMessages = client.sendAs("jane").getMessagesApi().list();
Is this somehow possible?
Or do I need to manually access the database for getting this info?

Related

Relationship between Teams Messaging Extension with action command, the underlying bot and access via Graph API

I want to call a messaging extension (with action command) and access Graph API via a bot for getting different resources of the channel (e.g. retrieve all messages or get replies for my message).
In the examples from Microsoft it is stated as a prerequisite that I have to do the "Bot channels registration" so that the access of the bot to the Graph API via OAuth2 works.
Do I really need this channel registration? Or is there another way?
As a test, I had created a azure free trial, with which I performed the "Bot channels registration" and could also save the ID and secret for the Graph Api access in the registration. With this I had success. Now the 30 days testing period is over and I'm interested in whether it would work without.
Thanks for your help
Update:
Thats my code to initialize graph api:
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(AppId)
.WithClientSecret(AppSecret)
.WithAuthority(new Uri($"https://login.microsoftonline.com/{Tenant}"))
.Build();
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
AuthenticationResult authenticationResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
return Task.FromResult(0);
}));
For OAuth authentication, you need to register the bot with azure for sure.

Unable to send message to Teams via the ConnectorClient bot connector

I am attempting to send a message to a Teams Channel from within a proactive 3rd party WebHook callback that resides in my Teams Bot which is triggered externally some time after my bot conversation has ended.
My config.ServiceURL is 'https://smba.trafficmanager.net/amer/' which I got from my bot while conversing in a session.
My config.MicrosoftAppId value is the ApplicationID assigned to my bot App registration in Azure.
My config.MicrosoftAppPassword is a Client secret I created for the registered bot App.
My ChannelInfo value is the value I discovered by enumerating all the target team's channels in another application. I replaced the actual values with 'f's.
In Azure I added the following permission to my registered App: Delegate - Group.ReadWrite.All
When I attempt to create the conversation I get a Forbidden response. If I change my ChannelInfo below to a bogus value I receive a Not Found response as expected so at least the ChannelInfo appears to be a valid value.
Is there another permission I need to add? Have I missed step? Is there something I did wrong?
Here is the code:
AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
var credentials = new MicrosoftAppCredentials(config.MicrosoftAppId, config.MicrosoftAppPassword);
if (!MicrosoftAppCredentials.IsTrustedServiceUrl(config.ServiceURL))
{
MicrosoftAppCredentials.TrustServiceUrl(config.ServiceURL);
}
var serviceUri = new Uri(config.ServiceURL);
var botConnector = new ConnectorClient(serviceUri, credentials);
Activity message = (Activity)Activity.CreateMessageActivity();
message.Text = "Hello World";
var conversationParameters = new ConversationParameters
{
Bot = message.From,
IsGroup = true,
ChannelData = new TeamsChannelData
{
Channel = new ChannelInfo("19:ffffffffffffffffffffffffffffffff#thread.skype")
},
Activity = (Activity)message
};
var conversationResponse = await botConnector.Conversations.CreateConversationAsync(conversationParameters);
await botConnector
.Conversations
.SendToConversationAsync(message);
Your code worked fine for me. Here's a few things you can try:
Ensure you sideloaded your bot into Teams via App Studio or manifest upload and that you're not just talking with the bot by appId
Ensure your bot is installed to the Team you want it to message
Add the domain your bot is hosted on to the Valid Domains section of the bot manifest
Esure you're sending the message to the correct conversation by changing .SendToConversationAsync(message); to .SendToConversationAsync(conversationResponse.Id, message);
Also note that the Microsoft.Bot.Builder.Teams package has been deprecated now that Bot<->Teams functionality has been rolled directly into the Bot Framework SDK. I highly recommend migrating away from it.
You may want to send proactive messages as shown in this sample. The other Teams Samples are numbers 50-60.
Let me know if you want to stick with that package and I can continue trying to provide support.

Microsoft Bot Framework: Determining user's Web Chat session availability

My scenario is to send an event or message to user's session to check if he is active or not.
I have the conversationId, Bot Channel Account and user connection details already.
I followed the same steps as mentioned here.
The issue that see is, irrespective of whether user is active or not, i always get ConversationId as the response, which does'nt help me to determine the session availability. I think, my event or message is getting ignored if session is not available.
Can somebody help me here please?
Adding more information :
My requirement is to update the status of all the inactive users.
I have all the respective conversationIds of the sessions that these users were part of.
To determine whether user is still active on web chat(meaning, he has'nt closed the webchat window), I am sending an event activity from bot to that user's session by providing the conversationId that we have for that session.
Below is the sample code snippet.
var eventActivity = Activity.CreateEventActivity();
eventActivity.From = user.Bot.ChannelAccount;
eventActivity.Recipient = user.Connection.ChannelAccount;
eventActivity.Conversation = user.Connection.ConversationAccount;
eventActivity.Value = userSession;
eventActivity.Name = message.Name;
var connector = new ConnectorClient(new Uri(user.Connection.ServiceLink));
var response = await connector.Conversations.SendToConversationAsync((Activity)eventActivity).ConfigureAwait(false);
userSession here contains two properties UPN and ConversationId that uniquely identifies the session.
Also, This UserSession's ConversationId is same as user.Connection.ConversationAccount.ConversationId.
Below image contains the User.Bot and user.Connection objects.
Bot&Connection_Objects

How to send message to another user via bot and come back to original conversation with first user without losing the context?

I am trying to build a bot that can address the requests placed by the user. However, the bot needs to ask permission of the user's manager for the same. So this is the flow:
User places a request to the bot.
Bot informs user's manager to either approve or reject the request
Based on the response from manager, bot either address the request or does not and informs the user.
I am able to make a 1:1 conversation between bot and user using the PromptDialog, and perform steps 1 and 3. However, I am not sure how to send message to another user for approval or rejection and continue the earlier conversation with the first user. I am using C# for this bot. Any ideas on how could I do this?
Thanks
Niyati
After sending the message to a second user using the following code and storing in the inbox of the first user, you can send the stored result, again using the above code, to the first user and follow their conversations.
string recipientId ="123456789"; // For Example
string serviceUrl = "https://telegram.botframework.com"; // For Example
var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, recipientId);
newMessage.Recipient = new ChannelAccount(recipientId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);
The code comes from here.
check this page, specifically the start conversation section.
You could keep a context stack for each user, pushing an item on top of the stack for each message sent by the bot and matching context in FIFO order for each message recieved. Now this context stack goes into a map identified by the userId/userKey.
Bot-context is a library which does exactly this. The related blog post.

Using EWS API to search through different users mailboxes

We are developing a module with the main goal being to track and collect information about damage inspections (insurance market). Each case has a code (e.g. L000525). Each case could be managed by several people. All the emails related to a specific case include the case code in the subject.
What we want to do is to collect and show the incoming and sent emails related to each specific case.
The idea is that any user can open a "Case management" window, select an specific case, and then get all the related information (including the emails of course).
We have to find the emails into the the mailboxes of around 20 users. So the questions are:
Which is the better way to do this? Will it consume a lot of time and resources?
We are new in the Exchange world so we are thinking Exchange impersonation, but we are not sure at all. The module is developed in Silverlight 3, WCF, SQL Server + Exchange 2007.
If the credentials used to connect to EWS have rights to access a user's mailbox then you should be able to do something like this:
var service = new ExchangeService();
service.Credentials = new WebCredentials("user_with_access#example.com", "password");
service.AutodiscoverUrl("a_valid_user#example.com");
var userMailbox = new Mailbox("target_user#example.com");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);
var itemView = new ItemView(20); // page size
var userItems = service.FindItems(folderId, itemView);
foreach (var item in userItems)
{
// do something with item (nb: it might not be a message)
}
That's it. Wow, my first SO answer!
A full working example of what #smcintosh has done above is here: Office365 API - Admin accessing another users/room's calendar events. It is a full java class that should compile and run and accesses a room resource calendar. Good luck!

Resources