/
BotBuilderCloudAdapter.ConversationBot.yml
212 lines (173 loc) · 6.37 KB
/
BotBuilderCloudAdapter.ConversationBot.yml
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
### YamlMime:TSType
name: ConversationBot
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot'
package: '@microsoft/teamsfx'
summary: >+
Provide utilities for bot conversation, including:
- handle command and response.
- send notification to varies targets (e.g., member, group, channel).
**Example**
For command and response, you can register your commands through the
constructor, or use the `registerCommand` and `registerCommands` API to add
commands later.
```typescript
import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
// register through constructor
const conversationBot = new ConversationBot({
command: {
enabled: true,
commands: [ new HelloWorldCommandHandler() ],
},
});
// register through `register*` API
conversationBot.command.registerCommand(new HelpCommandHandler());
```
For notification, you can enable notification at initialization, then send
notifications at any time.
```typescript
import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
// enable through constructor
const conversationBot = new ConversationBot({
notification: {
enabled: true,
},
});
// get all bot installations and send message
for (const target of await conversationBot.notification.installations()) {
await target.sendMessage("Hello Notification");
}
// alternative - send message to all members
for (const target of await conversationBot.notification.installations()) {
for (const member of await target.members()) {
await member.sendMessage("Hello Notification");
}
}
```
fullName: ConversationBot
remarks: >-
Set `adapter` in
[ConversationOptions](xref:@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationOptions)
to use your own bot adapter.
For command and response, ensure each command should ONLY be registered with
the command once, otherwise it'll cause unexpected behavior if you register
the same command more than once.
For notification, set `notification.storage` in
[ConversationOptions](xref:@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationOptions)
to use your own storage implementation.
isDeprecated: false
type: class
constructors:
- name: ConversationBot(ConversationOptions_2)
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.constructor'
package: '@microsoft/teamsfx'
summary: Create new instance of the `ConversationBot`.
remarks: >-
It's recommended to create your own adapter and storage for production
environment instead of the default one.
isDeprecated: false
syntax:
content: 'new ConversationBot(options: ConversationOptions_2)'
parameters:
- id: options
type: >-
<xref
uid="@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationOptions"
/>
description: The initialize options.
properties:
- name: adapter
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.adapter'
package: '@microsoft/teamsfx'
summary: The bot adapter.
fullName: adapter
remarks: ''
isDeprecated: false
syntax:
content: 'adapter: CloudAdapter'
return:
description: ''
type: CloudAdapter
- name: cardAction
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.cardAction'
package: '@microsoft/teamsfx'
summary: The action handler used for adaptive card universal actions.
fullName: cardAction
remarks: ''
isDeprecated: false
syntax:
content: 'cardAction?: CardActionBot_2'
return:
description: ''
type: <xref uid="@microsoft/teamsfx.BotBuilderCloudAdapter.CardActionBot" />
- name: command
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.command'
package: '@microsoft/teamsfx'
summary: The entrypoint of command and response.
fullName: command
remarks: ''
isDeprecated: false
syntax:
content: 'command?: CommandBot_2'
return:
description: ''
type: <xref uid="@microsoft/teamsfx.BotBuilderCloudAdapter.CommandBot" />
- name: notification
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.notification'
package: '@microsoft/teamsfx'
summary: The entrypoint of notification.
fullName: notification
remarks: ''
isDeprecated: false
syntax:
content: 'notification?: NotificationBot_2'
return:
description: ''
type: >-
<xref uid="@microsoft/teamsfx.BotBuilderCloudAdapter.NotificationBot"
/>
methods:
- name: >-
requestHandler(Request<Record<string, unknown>, Record<string, undefined |
string | string[]>>, Response, (context: TurnContext) => Promise<any>)
uid: '@microsoft/teamsfx.BotBuilderCloudAdapter.ConversationBot.requestHandler'
package: '@microsoft/teamsfx'
summary: |+
The request handler to integrate with web request.
**Example**
For example, to use with Restify:
``` typescript
// The default/empty behavior
server.use(restify.plugins.bodyParser());
server.post("api/messages", conversationBot.requestHandler);
// Or, add your own logic
server.use(restify.plugins.bodyParser());
server.post("api/messages", async (req, res) => {
await conversationBot.requestHandler(req, res, async (context) => {
// your-own-context-logic
});
});
```
remarks: ''
isDeprecated: false
syntax:
content: >-
function requestHandler(req: Request<Record<string, unknown>,
Record<string, undefined | string | string[]>>, res: Response, logic?:
(context: TurnContext) => Promise<any>): Promise<void>
parameters:
- id: req
type: >-
Request<Record<string, unknown>, Record<string,
undefined | string | string[]>>
description: An incoming HTTP [Request](xref:botbuilder.Request).
- id: res
type: Response
description: The corresponding HTTP [Response](xref:botbuilder.Response).
- id: logic
type: '(context: TurnContext) => Promise<any>'
description: The additional function to handle bot context.
return:
description: ''
type: Promise<void>