Beispiel #1
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Replace with your own message
                //System.Diagnostics.Debug.WriteLine("message");
                IActivity replyActivity = MessageFactory.Text($"Message");

                // Replace with your own condition for bot escalation
                if (turnContext.Activity.Text.Equals("escalate", StringComparison.InvariantCultureIgnoreCase))

                {
                    replyActivity = MessageFactory.Text($"TROCANDO PARA UM AGENTE");
                    //System.Diagnostics.Debug.WriteLine("escalate");
                    Dictionary <string, object> contextVars = new Dictionary <string, object>()
                    {
                        { "BotHandoffTopic", "troca" }
                    };
                    OmnichannelBotClient.AddEscalationContext(replyActivity, contextVars);
                }
                // Replace with your own condition for bot end conversation
                else if (turnContext.Activity.Text.Equals("endconversation", StringComparison.InvariantCultureIgnoreCase))
                {
                    OmnichannelBotClient.AddEndConversationContext(replyActivity);
                }
                // Call method BridgeBotMessage for every response that needs to be delivered to the customer.
                else
                {
                    OmnichannelBotClient.BridgeBotMessage(replyActivity);
                }

                await turnContext.SendActivityAsync(replyActivity, cancellationToken);
            }
        }
Beispiel #2
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            try
            {
                var httpClient = new HttpClient();

                var qnaMaker = new QnAMaker(new QnAMakerEndpoint
                {
                    KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
                    EndpointKey     = _configuration["QnAAuthKey"],
                    Host            = GetHostname(_configuration["QnAEndpointHostName"])
                },
                                            null,
                                            httpClient);

                var options = new QnAMakerOptions {
                    Top = 1
                };

                // The actual call to the QnA Maker service.
                var response = await qnaMaker.GetAnswersAsync(turnContext, options);

                IActivity replyActivity = MessageFactory.Text($"{response[0].Answer}");

                // Replace with your own condition for bot escalation
                if (turnContext.Activity.Text.Equals("escalate", StringComparison.InvariantCultureIgnoreCase))
                {
                    Dictionary <string, object> contextVars = new Dictionary <string, object>()
                    {
                        { "BotHandoffTopic", "CreditCard" }
                    };
                    OmnichannelBotClient.AddEscalationContext(replyActivity, contextVars);
                }
                // Replace with your own condition for bot end conversation
                else if (turnContext.Activity.Text.Equals("endconversation", StringComparison.InvariantCultureIgnoreCase))
                {
                    OmnichannelBotClient.AddEndConversationContext(replyActivity);
                }
                // Call method BridgeBotMessage for every response that needs to be delivered to the customer.
                else
                {
                    OmnichannelBotClient.BridgeBotMessage(replyActivity);
                }

                //await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);

                await turnContext.SendActivityAsync(replyActivity, cancellationToken);
            }

            catch (Exception ex)
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(ex.ToString()), cancellationToken);
            }
        }
Beispiel #3
0
        /*private static Attachment CreateAdaptiveCardAttachment(string filePath)
         * {
         *  var adaptiveCardJson = File.ReadAllText(filePath);
         *  var adaptiveCardAttachment = new Attachment()
         *  {
         *      ContentType = "application/vnd.microsoft.card.adaptive",
         *      Content = JsonConvert.DeserializeObject(adaptiveCardJson),
         *  };
         *  return adaptiveCardAttachment;
         * } */

        protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    OmnichannelBotClient.BridgeBotMessage(turnContext.Activity);
                    await turnContext.SendActivityAsync(MessageFactory.Text($"Hello! Welcome!"), cancellationToken);
                }
            }
        }
Beispiel #4
0
 protected override async Task OnMembersAddedAsync(IList <ChannelAccount> membersAdded, ITurnContext <IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
 {
     foreach (var member in membersAdded)
     {
         if (member.Id != turnContext.Activity.Recipient.Id)
         {
             //Set the bridge mode for every message that needs to be delivered to customer
             OmnichannelBotClient.BridgeBotMessage(turnContext.Activity);
             await turnContext.SendActivityAsync(MessageFactory.Text($"Welcome to Echo Bot."), cancellationToken);
         }
     }
 }
Beispiel #5
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            try
            {
                var httpClient = new HttpClient();

                var qnaMaker = new QnAMaker(new QnAMakerEndpoint
                {
                    KnowledgeBaseId = "461a9694-ee84-4423-b283-600e2e978b0c", //_configuration["QnAKnowledgebaseId"],
                    EndpointKey     = "39b9495c-b1a8-4a87-ac23-ad566a40dd80", //_configuration["QnAEndpointKey"],
                    Host            = GetHostname("mooqna.azurewebsites.net") //_configuration["QnAEndpointHostName"])
                },
                                            null,
                                            httpClient);

                var options = new QnAMakerOptions {
                    Top = 1
                };

                // The actual call to the QnA Maker service.
                var response = await qnaMaker.GetAnswersAsync(turnContext, options);

                IActivity replyActivity = MessageFactory.Text($"{response[0].Answer}");

                // Replace with your own condition for bot escalation
                if (turnContext.Activity.Text.Equals("escalate", StringComparison.InvariantCultureIgnoreCase))
                {
                    Dictionary <string, object> contextVars = new Dictionary <string, object>()
                    {
                        { "BotHandoffTopic", "CreditCard" }
                    };
                    OmnichannelBotClient.AddEscalationContext(replyActivity, contextVars);
                }
                // Replace with your own condition for bot end conversation
                else if (turnContext.Activity.Text.Equals("endconversation", StringComparison.InvariantCultureIgnoreCase))
                {
                    OmnichannelBotClient.AddEndConversationContext(replyActivity);
                }
                // Call method BridgeBotMessage for every response that needs to be delivered to the customer.
                else
                {
                    OmnichannelBotClient.BridgeBotMessage(replyActivity);
                }

                await turnContext.SendActivityAsync(replyActivity, cancellationToken);
            }

            catch (Exception ex)
            {
                await turnContext.SendActivityAsync(MessageFactory.Text(ex.ToString()), cancellationToken);
            }
        }