This repository was archived by the owner on Jun 20, 2025. It is now read-only.
forked from microsoft/CopilotStudioSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandoffHelper.cs
More file actions
47 lines (40 loc) · 2.13 KB
/
Copy pathHandoffHelper.cs
File metadata and controls
47 lines (40 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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>
}
}
}
}