forked from BotBuilderCommunity/botbuilder-community-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleContextExtensions.cs
158 lines (143 loc) · 5.82 KB
/
GoogleContextExtensions.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Bot.Builder.Community.Adapters.Google.Model;
using Microsoft.Bot.Builder;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Bot.Builder.Community.Adapters.Google
{
public static class GoogleContextExtensions
{
public static void GoogleSetChoicePromptHelper(this ITurnContext context, string title, List<GoogleOptionItem> items)
{
var optionSystemIntent = new OptionSystemIntent()
{
Data = new OptionSystemIntentData
{
ListSelect = new OptionIntentListSelect
{
Title = title,
}
}
};
foreach (var item in items)
{
optionSystemIntent.Data.ListSelect.Items = new List<OptionIntentSelectListItem>();
optionSystemIntent.Data.ListSelect.Items.Add(
new OptionIntentSelectListItem()
{
OptionInfo = new SelectListItemOptionInfo
{
Key = item.Key,
Synonyms = item.Synonyms
},
Description = item.Description,
Title = item.Title,
Image = new SelectListItemOptionImage
{
Url = item.ImageUrl,
AccessibilityText = item.ImageAccessibilityText
}
});
}
context.TurnState.Add("systemIntent", optionSystemIntent);
}
public static void GoogleSetCard(this ITurnContext context, GoogleBasicCard card)
{
context.TurnState.Add("GoogleCard", card);
}
public static void GoogleSetCard(this ITurnContext context, string title,
string subtitle, Image image, ImageDisplayOptions imageDisplayOptions,
string formattedText)
{
if (image == null && formattedText == null)
{
throw new Exception("A Basic Card should have either an Image or Formatted Text set");
}
// Fixed
var card = new GoogleBasicCard()
{
Content = new GoogleBasicCardContent()
{
Title = title,
Subtitle = subtitle,
FormattedText = formattedText,
Display = ImageDisplayOptions.DEFAULT,
Image = image
},
};
// Just leaving this as commented to give developers a glimpse of implementation.
//var card = new GoogleBasicCard()
//{
// Content = new GoogleBasicCardContent()
// {
// Title = "This is the card title",
// Subtitle = "This is the card subtitle",
// FormattedText = "This is some text to go into the card." +
// "**This text should be bold** and " +
// "*this text should be italic*.",
// Display = ImageDisplayOptions.DEFAULT,
// Image = new Image()
// {
// AccessibilityText = "This is the accessibility text",
// Url = "https://dev.botframework.com/Client/Images/ChatBot-BotFramework.png"
// },
// },
//};
context.TurnState.Add("GoogleCard", card);
}
public static void GoogleAddSuggestionChipsToResponse(this ITurnContext context, List<Suggestion> suggestionChips)
{
context.TurnState.Add("GoogleSuggestionChips", suggestionChips);
}
public static void GoogleSetMediaResponse(this ITurnContext context, MediaResponse mediaResponse)
{
context.TurnState.Add("GoogleMediaResponse", mediaResponse);
}
public static void GoogleSetAudioResponse(this ITurnContext context,
string audioUrl, string name, string description = null,
Image icon = null, Image largeImage = null)
{
var mediaResponse = new MediaResponse()
{
Content = new MediaResponseContent()
{
MediaType = MediaType.AUDIO,
MediaObjects = new MediaObject[]
{
new MediaObject()
{
ContentUrl = audioUrl,
Description = description,
Name = name,
Icon = icon,
LargeImage = largeImage,
},
},
},
};
context.GoogleSetMediaResponse(mediaResponse);
}
public static Payload GetGoogleRequestPayload(this ITurnContext context)
{
try
{
return (Payload)context.Activity.ChannelData;
}
catch (Exception ex)
{
return null;
}
}
public static List<string> GoogleGetSurfaceCapabilities(this ITurnContext context)
{
var payload = (Payload)context.Activity.ChannelData;
var capabilities = payload.Surface.Capabilities.Select(c => c.Name);
return capabilities.ToList();
}
}
}