Mark Hawkins-Wood
Mark Hawkins-Wood

Reputation: 43

Microsoft Bot Framework - How to get user data from team channel

I have a LUIS Intent in my ChatBot to send an email as a user (code below). At the moment it sends an email as me, to me (but sending from an automation mailbox with permissions to send from everyones mailbox). I want it to read the properties of the user who is interacting with the bot in MS Teams and use that users email address instead?

 [LuisIntent("Endpoint_CreateTicket")]
    public async Task EndpointCreateTicketIntent(IDialogContext context, LuisResult result)
    {
        using (SmtpClient client = new SmtpClient())
        {
            using (MailMessage message = new MailMessage())
            {
                client.Host = "smtp.office365.com";
                client.Port = 587;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential("<confidential>", "<confidential>");
                client.EnableSsl = true;
                message.From = new MailAddress("[email protected]");
                message.Subject = "THIS IS THE SUBJECT";
                message.Body = "THIS IS THE BODY";
                message.To.Add("[email protected]");
                try
                {
                    client.Send(message);
                }
                catch(Exception e)
                {
                    await context.PostAsync(e.Message);
                }
            }
        }
    }

Upvotes: 0

Views: 743

Answers (1)

John Nyingi
John Nyingi

Reputation: 1110

You should have an Intent to extract email. Example you can have an intent called ExtractEmail type Email

a user can input something like my email is [email protected],

hence your LUIS JSON response returns something like

"entities": [
{
  "entity": "[email protected]",
  "type": "Email",
  "startIndex": 18,
  "endIndex": 22,
  "score": 0.9866132
}]

From your function try this

 using System.Net.Mail;

 try{
  MailAddress mail = new MailAddress(result.entity);
  message.From  = mail;
 }
 catch(Exception){
      //Reply with an error
  }

More information on Intents

Upvotes: 1

Related Questions