Commit bdfceb4e authored by dasharatha.vamshi's avatar dasharatha.vamshi

agent-handoff

parent c849b8b7
...@@ -6,19 +6,80 @@ using System; ...@@ -6,19 +6,80 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using RestSharp;
using Newtonsoft.Json.Linq;
namespace IntermediatorBotSample.Bot namespace IntermediatorBotSample.Bot
{ {
public class IntermediatorBot : IBot public class IntermediatorBot : IBot
{ {
private const string SampleUrl = "https://github.com/tompaana/intermediator-bot-sample"; private const string SampleUrl = "https://github.com/tompaana/intermediator-bot-sample";
public int flag = 0;
public async Task OnTurnAsync(ITurnContext context, CancellationToken ct) public async Task OnTurnAsync(ITurnContext context, CancellationToken ct)
{ {
Command showOptionsCommand = new Command(Commands.ShowOptions); var singleton = Singleton.GetInstance();
await context.SendActivityAsync("text --> " + context.Activity.Text + "conv-id --> " + context.Activity.Conversation.Id); var question = "";
if((string)context.Activity.Text== null)
{
flag = 1;
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + "Hi");
await context.SendActivityAsync("Hi");
}
//Command showOptionsCommand = new Command(Commands.ShowOptions);
//await context.SendActivityAsync("text --> " + context.Activity.Text + "conv-id --> " + context.Activity.Conversation.Id);
try
{
question = (string)context.Activity.Text;
//var len = question.Trim().Length;
}
catch
{
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + "Thank you for your patience as I am learning. In an effort to help you, please rephrase your question.");
await context.SendActivityAsync("How may I help you today?");
}
try
{
var client = new RestClient("https://azr-qna-fsl-tst-vaboten.azurewebsites.net/qnamaker/knowledgebases/c462e3b6-5c2a-4ccc-8e07-628508062f2b/generateAnswer");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "EndpointKey 5b214fe6-7dba-46fd-9968-c63a83407b0a");
request.AddHeader("Content-Type", "application/json");
string body = string.Format("\"question\":\"{0}\"", question);
string body1 = "{\r\n " + body + "\r\n}";
JObject json = JObject.Parse(body1);
request.AddParameter("application/json", json, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
var body2 = JObject.Parse(response.Content);
var answer = body2["answers"][0]["answer"];
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + answer.ToString().Replace("?","."));
await context.SendActivityAsync(answer.ToString());
}
catch
{
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + "How may I help you.");
await context.SendActivityAsync("How may I help you?");
}
HeroCard heroCard = new HeroCard() /*HeroCard heroCard = new HeroCard()
{ {
Title = "Hello!", Title = "Hello!",
Subtitle = "I am Intermediator Bot", Subtitle = "I am Intermediator Bot",
...@@ -32,14 +93,17 @@ namespace IntermediatorBotSample.Bot ...@@ -32,14 +93,17 @@ namespace IntermediatorBotSample.Bot
Type = ActionTypes.ImBack Type = ActionTypes.ImBack
} }
} }
}; };*/
var singleton = Singleton.GetInstance();
singleton.Log("bot_message: " + "hero card displayed");
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + "hero card displayed");
Activity replyActivity = context.Activity.CreateReply(); /*singleton.Log("bot_message: " + "hero card displayed");
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " bot_message: " + "hero card displayed");
*/
/*Activity replyActivity = context.Activity.CreateReply();
replyActivity.Attachments = new List<Attachment>() { heroCard.ToAttachment() }; replyActivity.Attachments = new List<Attachment>() { heroCard.ToAttachment() };
await context.SendActivityAsync(replyActivity); await context.SendActivityAsync(replyActivity);*/
} }
} }
} }
...@@ -126,13 +126,13 @@ namespace IntermediatorBotSample.Middleware ...@@ -126,13 +126,13 @@ namespace IntermediatorBotSample.Middleware
// Check for cry for help (agent assistance) // Check for cry for help (agent assistance)
var singleton = Singleton.GetInstance(); var singleton = Singleton.GetInstance();
if (!string.IsNullOrWhiteSpace(activity.Text) if (!string.IsNullOrWhiteSpace(activity.Text)
&& activity.Text.ToLower().Contains("human")) && (activity.Text.ToLower().Contains("human") | (activity.Text.ToLower().Contains("escalate"))))
{ {
// Create a connection request on behalf of the sender // Create a connection request on behalf of the sender
// Note that the returned result must be handled // Note that the returned result must be handled
singleton.Log( "input_message: " + context.Activity.Text); singleton.Log( "input_message: " + context.Activity.Text);
singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " input_message: " + context.Activity.Text); singleton.addToLog(context.Activity.Conversation.Id, "{" + DateTime.Now.ToLongTimeString().ToString() + "}" + " input_message: " + context.Activity.Text);
await context.SendActivityAsync("text --> " + context.Activity.Text + " conv-id --> " + context.Activity.Conversation.Id); //await context.SendActivityAsync("text --> " + context.Activity.Text + " conv-id --> " + context.Activity.Conversation.Id);
//singleton.Log("end"); //singleton.Log("end");
List<string> x = singleton.final_msg(); List<string> x = singleton.final_msg();
for (int i=0;i<x.Count;i++) for (int i=0;i<x.Count;i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment