MS BotFramework: collecting users credentials - botframework

Apologies for the lack of code or detail but I honestly don't know where to start!
I am building a bot to run a couple of reports and update a bunch of stuff in SharePoint (currently 2013 but moving to Online later in 2017).
I don't want to store them in plain text within the folder structure of my bot but I don't want them visible when you type them into the chat bot either.
Is there a way to asterisk out the password as the user types it in?
Cheers!

Per my understanding, you want to mask the password input for your users. If any misunderstanding, please feel free to let me know.
So it seems that there is a similar question in GitHub at [Question] Masking Password field in Adaptive Card?
Password masking is not currently a feature. We recommend using the Sign-in Card workflow.
Using Sign-in card:
Activity replyToConversation = message.CreateReply("Should go to conversation");
replyToConversation.Attachments = new List<Attachment>();
List<CardAction> cardButtons = new List<CardAction>();
CardAction plButton = new CardAction()
{
Value = $"https://<OAuthSignInURL",
Type = "signin",
Title = "Connect"
};
cardButtons.Add(plButton);
SigninCard plCard = new SigninCard(title: "You need to authorize me", button: plButton);
Attachment plAttachment = plCard.ToAttachment();
replyToConversation.Attachments.Add(plAttachment);
var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
Then leverage https://github.com/MicrosoftDX/AuthBot in your bot for authentication.

Related

How to pass the password activity form bot to the front end in microsoft bot framework

I am trying to implement the functionality of the password as shown in this link.
https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/05.custom-components/f.password-input
but how to pass the password activity form the bot to the front end. I am using the c# template for the developing the bot.
As per my understanding, we need to pass a password activity from the bot to the front-end for the execution of the password things as mentioned in the link.
An example would be help-full in knowing how to pass this type of customer activity forms the bot.
Thanks,
I used this sample myself for one of my bots. The bot logic is built in node but I guess it shouldn't be hard to translate to c#
const askPwd =
{
name: 'passwordInput',
type: 'event'
};
await stepContext.context.sendActivity(askPwd);
return await stepContext.prompt(PASSWORD_PROMPT, '');
In c# this will probabaly translate into something like this (I don't know c#):
Activity activity = new Activity
{
Type = ActivityTypes.Event,
Name = "passwordInput"
};
await stepContext.Context.SendActivityAsync(activity, cancellationToken);});

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.

Bot Framework v4 - Bot Initiate Conversation

I am developing a bot for Microsoft Teams using the Bot Framework SDK v4 for NodeJS. Is there a way that the bot can automatically initiate a conversation in a channel, rather than user initiating the conversation? My bot works fine when the user initiates the conversation. Any suggestions on how I can proceed with this?
MS Teams calls that a "Proactive Message" (note: Bot Framework generally defines a "proactive message" as sending a user a message not related to current conversation, that you have a reference for. Teams lumps a few things into this category). You can read more about how to use proactive messaging from the official Teams docs. Or, more specifically, creating a channel conversation.
The gist of it is that you need to capture a conversationUpdate and check for a new member added to the conversation or fetch the team roster, then you send the proactive message.
Note: For MS Teams, the user or team will have to add the bot first:
Bots can create new conversations with an individual Microsoft Teams user as long as your bot has user information obtained through previous addition in a personal or team scope. This information enables your bot to proactively notify them. For instance, if your bot was added to a team, it could query the team roster and send users individual messages in personal chats, or a user could #mention another user to trigger the bot to send that user a direct message.
Some developers come across 401: Unauthorized errors when using proactive messaging, especially if the bot was restarted for some reason and the bot is attempting to re-initiate a proactive message. You can read more about preventing that by using trustServiceUrl from this Sample (this is my branch, which is being used to submit a Pull Request to update the Proactive Sample with trustServiceUrl info).
You can initiate a brand new conversation using the connector Client in the Botframework V4 and the Teams Extensions V4. In nodejs, you will find a solution in one of the comments for this Github Issue. For anyone looking for a solution in C#, here is a detailed blog post about accomplishing this in C# version of the botframework.
in nodejs :
var conversationReference = TurnContext.getConversationReference(context.activity)
connectorClient = await createConnectorClient(context)
var conversationParameters = {
isGroup: true,
bot: conversationReference.bot,
channelData: (await teamsCtx.getTeamsChannelData()),
tenantId: teamsCtx.tenant.id,
activity: MessageFactory.text("Queue Summary Placeholder") as Activity
} as ConversationParameters
await connectorClient.conversations.createConversation(conversationParameters)
In C#
ConnectorClient _client = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), await GetMicrosoftAppCredentialsAsync(turnContext), new HttpClient());
var channelData = turnContext.Activity.GetChannelData<TeamsChannelData>();
var conversationParameter = new ConversationParameters
{
Bot = turnContext.Activity.Recipient,
IsGroup = true,
ChannelData = channelData,
TenantId = channelData.Tenant.Id,
Activity = MessageFactory.Text(message)
};
var response = await _client.Conversations.CreateConversationAsync(conversationParameter);
Really we need to know when you want the bot to send the message, the bot framework TeamsActivityHandler class provides multiple methods that you can utilise for example:
onMembersAdded(BotHandler): Registers an activity event handler for the members added event, emitted for any incoming conversation update activity that includes members added to the conversation.
Learn more about the events / methods you can utilise here.
I ended up figuring it out and i wrote a bot controller that i can invoke on demand with the following code.
var conversationParameters = new ConversationParameters
{
IsGroup = true,
ChannelData = new TeamsChannelData
{
// this needs to come from the teams context.
Channel = new ChannelInfo(channelId),
},
Activity = (Activity)MessageFactory.Attachment(attachment)
};
// your service url may differ.
MicrosoftAppCredentials.TrustServiceUrl(String.IsNullOrEmpty(serviceUrl) ? constantServiceUrl : serviceUrl, DateTime.MaxValue);
var response = connectorClient.Conversations.CreateConversationAsync(conversationParameters).GetAwaiter().GetResult();

Microsoft Bot Framework (Node.js- SDK4) + Microsoft Graph API

Is it possible that the Microsoft Bot Framework Node.js - SDK4 automatically identify a logged in user from a Microsoft account (like a user that is logged in Sharepoint) so that I can use Microsoft Graph services directly on the bot without needing to ask user login and password?
I'm asking that because I have a bot running on a sharepoint page, and in theory, the user already will be logged in on a microsoft account when he starts talking to the bot.
Check this code.
{ ResponseIds.Greeting, (context, data) => {
var greetings = JsonConvert.DeserializeObject<Greetings>
(MainStrings.GREETING);
Random r = new Random( );
int index = r.Next( greetings.messages.Count );
return greetings.messages[index].message.Replace("
{username}",context.Activity.From.Name);
}
Else I have seen an authentication dialog that probably does a similar operation

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