Search code examples
emailbotframeworkazure-qna-maker

How to configure the mail channel of a QnA Bot?


I'm working in a bot that uses a QnA Service to answer some questions. I set up channels like mail or Microsoft Teams so the bot can respond the answers there. I wanted to configure the mail channel so it responds if the subject is a particular one.

I don't see any option to configure it where you link the bot to the mail channel:

Is there any way to configure it?


Solution

  • Email channel configuration with the bot and making your logic work are two different things.

    • First, you need to link your bot to the email channel by entering your Office 365 email credentials and click on 'Save'. The screenshot which you have attached above just needs you to enter your credentials which would connect your QnA Bot to your email account.
    • Now, on to the part where you want the bot to respond if the subject line is a particular one. That basically means that you will be checking the channel data to see if the subject line is saved, then checking that the subject line contains a certain word or a sentence and if it does, then respond.

    This documentation will enable you to pass native metadata to a channel in the activity object's channel data property.

    For example,the JSON object of the channelData property for a custom email message is shown below:

    "channelData": {
        "type": "message",
        "locale": "en-Us",
        "channelID": "email",
        "from": { "id": "[email protected]", "name": "My bot"},
        "recipient": { "id": "[email protected]", "name": "Joe Doe"},
        "conversation": { "id": "123123123123", "topic": "awesome chat" },
        "channelData":
        {
            "htmlBody": "<html><body style = /"font-family: Calibri; font-size: 11pt;/" >This is more than awesome.</body></html>",
            "subject": "Super awesome message subject",
            "importance": "high",
            "ccRecipients": "[email protected]"
        }
    }
    

    An example to set Email channel specific properties in ChannelData can be implemented such as:

     if (message.ChannelId == ChannelIds.Email)
    {
        var reply = message.CreateReply();
        reply.ChannelData = JObject.FromObject(new
        {
            htmlBody = "<html><body style=\"font-family: Calibri; font-size: 11pt;\">This is the email body!</body></html>",
            subject = "This is the email subject",
            importance = "high"
        });
        //send reply to user
        await context.PostAsync(reply);
    }
    

    Hope this helps.