Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ConnectToEngagementHub/Handoff/BotResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using Microsoft.Bot.Schema;
using Newtonsoft.Json;

namespace Microsoft.PVA.Handoff
{
/// <summary>
/// Activities that are received by the user in response to their query
/// </summary>
public class BotResponse
{
/// <summary>
/// Activities that are a part of the bot response
/// </summary>
[JsonProperty(PropertyName = "activities")]
public Activity[] Activities { get; set; }
}
}
77 changes: 77 additions & 0 deletions ConnectToEngagementHub/Handoff/HandoffContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using Newtonsoft.Json;

namespace Microsoft.PVA.Handoff
{
public class HandoffContext
{
/// <summary>
/// Scope of the activity - bot/user
/// </summary>
[JsonProperty(PropertyName = "va_Scope")]
public string Scope { get; set; }

/// <summary>
/// Last topic triggered in conversation
/// </summary>
[JsonProperty(PropertyName = "va_LastTopic")]
public string LastTopic { get; set; }

/// <summary>
/// All topics triggered in conversation
/// </summary>
[JsonProperty(PropertyName = "va_Topics")]
public string[] Topics { get; set; }

/// <summary>
/// Last user phrase
/// </summary>
[JsonProperty(PropertyName = "va_LastPhrase")]
public string LastPhrase { get; set; }

/// <summary>
/// All user phrases
/// </summary>
[JsonProperty(PropertyName = "va_Phrases")]
public string[] Phrases { get; set; }

/// <summary>
/// Conversation Id
/// </summary>
[JsonProperty(PropertyName = "va_ConversationId")]
public string ConversationId { get; set; }

/// <summary>
/// Message for agent as configured in dialog
/// </summary>
[JsonProperty(PropertyName = "va_AgentMessage")]
public string AgentMessage { get; set; }

/// <summary>
/// Bot Id
/// </summary>
[JsonProperty(PropertyName = "va_BotId")]
public string BotId { get; set; }

/// <summary>
/// Bot Name
/// </summary>
[JsonProperty(PropertyName = "va_BotName")]
public string BotName { get; set; }

/// <summary>
/// Language
/// </summary>
[JsonProperty(PropertyName = "va_Language")]
public string Language { get; set; }

/// <summary>
/// MS Caller Id
/// </summary>
[JsonProperty(PropertyName = "MSCallerId")]
public string MSCallerId { get; set; }
}
}
47 changes: 47 additions & 0 deletions ConnectToEngagementHub/HandoffHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using Microsoft.Bot.Schema;
using Newtonsoft.Json;
using System.Linq;

namespace Microsoft.PVA.Handoff
{
public static class HandoffHelper
{
private const string HandoffInitiateActivityName = "handoff.initiate";
private const string TranscriptAttachmentName = "transcript";

public static void InitiateHandoff(string botresponseJson)
{
BotResponse response = JsonConvert.DeserializeObject<BotResponse>(botresponseJson);

// Look for Handoff Initiate Activity. This indicates that conversation needs to be handed off to agent
Activity handoffInitiateActivity = response.Activities.ToList().FirstOrDefault(
item => string.Equals(item.Type, ActivityTypes.Event, System.StringComparison.Ordinal)
&& string.Equals(item.Name, HandoffInitiateActivityName, System.StringComparison.Ordinal));

if (handoffInitiateActivity != null)
{
// Read transcript from attachment
if (handoffInitiateActivity.Attachments?.Any() == true)
{
Attachment transcriptAttachment = handoffInitiateActivity.Attachments.FirstOrDefault(
a => string.Equals(a.Name.ToLowerInvariant(), TranscriptAttachmentName, System.StringComparison.Ordinal));
if (transcriptAttachment != null)
{
Transcript transcript = JsonConvert.DeserializeObject<Transcript>(
transcriptAttachment.Content.ToString());
}
}

// Read handoff context
HandoffContext context = JsonConvert.DeserializeObject<HandoffContext>(handoffInitiateActivity.Value.ToString());

// Connect to Agent Hub
// <YOUR CUSTOM ADAPTER CODE GOES HERE>
}
}
}
}
170 changes: 170 additions & 0 deletions ConnectToEngagementHub/activities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"activities": [
{
"type": "event",
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000005",
"timestamp": "2020-02-10T21:51:37.4997264Z",
"channelId": "directline",
"from": {
"id": "f074b91b-2f8c-4543-bbcc-7226e9662c01",
"name": "Test501",
"role": "bot"
},
"conversation": {
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o"
},
"attachments": [
{
"contentType": "application/json",
"content": {
"activities": [
{
"type": "message",
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000000",
"timestamp": "2020-02-10T21:51:21.491453+00:00",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "pva_H1YHD_be80720b-bdb0-4561-aae2-5f891f2f02e0",
"name": "C2 User",
"role": "user"
},
"conversation": {
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o"
},
"recipient": {
"id": "<REDACTED>",
"name": "Contoso Bot",
"role": "bot"
},
"textFormat": "plain",
"locale": "en-US",
"text": "store hours",
"entities": [
{
"type": "ClientCapabilities",
"requiresBotState": true,
"supportsListening": true,
"supportsTts": true
}
],
"channelData": {
"clientActivityID": "15813714814300.gevfmx9xoxc",
"cci_bot_id": "<REDACTED>",
"cci_tenant_id": "<REDACTED>",
"cci_content_version": "e8aa9c88-4249-ea11-a812-000d3a1531ec",
"cci_trace_id": "1xc8K",
"traceHistory": null,
"enableDiagnostics": true
},
"cci_bot_id": "<REDACTED>",
"cci_tenant_id": "<REDACTED>",
"cci_content_version": "e8aa9c88-4249-ea11-a812-000d3a1531ec"
},
{
"type": "message",
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000001",
"timestamp": "2020-02-10T21:51:30.6362632+00:00",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "<REDACTED>",
"name": "Contoso Bot",
"role": "bot"
},
"conversation": {
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o"
},
"recipient": {
"id": "pva_H1YHD_be80720b-bdb0-4561-aae2-5f891f2f02e0",
"name": "C2 User",
"role": "user"
},
"textFormat": "markdown",
"text": "I'm happy to help with store hours.",
"inputHint": "acceptingInput",
"attachments": [],
"entities": [],
"channelData": {
"DialogTraceDetail": {
"DialogTraces": [
{
"DialogId": "caf0a29a-bad7-40e0-9941-11925e17614b",
"NodeId": "e901982c-a22d-4074-b8c7-f7842977a047"
}
]
},
"ConversationUnderstandingDetail": {
"NormalizedQuery": "store hour",
"RawQuery": "store hours",
"ClarificationDetail": {
"ConfirmQuestion": false
},
"RankedIntents": [
{
"IntentId": "33d51237-70ba-4dae-afae-51b361ddc80a",
"Score": 1.0,
"MatchedTriggerQuery": "Store hours"
}
]
},
"VariableDetail": {
"Variables": {}
},
"CurrentMessageDetail": {
"TraceId": "1xc8K",
"ConversationId": "91hcXEd0ZYCBPoRwBDPHZ6-o",
"CurrentProblemId": "3858486c-f1d7-415a-8678-979f725c601b",
"CurrentIntentId": "33d51237-70ba-4dae-afae-51b361ddc80a",
"ContentVersion": "e8aa9c88-4249-ea11-a812-000d3a1531ec",
"SentTime": "2020-02-10T21:51:30.6092929+00:00"
}
},
"replyToId": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000000"
}
]
},
"name": "Transcript"
}
],
"entities": [],
"replyToId": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000000",
"value": {
"va_Scope": "bot",
"va_LastTopic": "Lesson 1 - A simple topic",
"va_Topics": [
"Lesson 1 - A simple topic"
],
"va_LastPhrase": "store hours",
"va_Phrases": [
"store hours"
],
"va_ConversationId": "91hcXEd0ZYCBPoRwBDPHZ6-o",
"va_AgentMessage": "Transferred",
"va_BotId": "<REDACTED>",
"va_BotName": "Test501",
"va_Language": "En-US"
},
"name": "handoff.initiate",
"relatesTo": {
"activityId": "91hcXEd0ZYCBPoRwBDPHZ6-o|0000000",
"user": {
"id": "pva_H1YHD_be80720b-bdb0-4561-aae2-5f891f2f02e0",
"name": "C2 User",
"role": "user"
},
"bot": {
"id": "<REDACTED>",
"name": "Contoso Bot",
"role": "bot"
},
"conversation": {
"id": "91hcXEd0ZYCBPoRwBDPHZ6-o"
},
"channelId": "directline",
"serviceUrl": "https://directline.botframework.com/"
}
}
],
"watermark": "5"
}