-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathculture.ts
56 lines (45 loc) · 1.58 KB
/
culture.ts
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
import { MemoryStorage, ConsoleAdapter } from 'botbuilder';
import { Topic, Culture, NumberPrompt, prettyConsole, WSTelemetry, Prompt, hasText, consoleOnTurn, doTopic, PromptArgs } from '../src/topical';
async function prompter (
this: Prompt<any, string>
) {
await this.send(this.state.args!);
}
class PromptForCulture extends Prompt<string> {
validator = hasText
.and((activity, text) => Culture.getSupportedCultureCodes().includes(text) || 'unsupported_culture');
}
PromptForCulture.register();
class FavoriteNumber extends Topic {
async onStart() {
await this.next();
}
async next() {
await this.startChild(PromptForCulture, {
prompt: `Please pick a culture (${Culture.getSupportedCultureCodes().join(', ')}).`
});
}
async onDispatch() {
if (this.text)
await this.dispatchToChild();
}
async onChildEnd(child: Topic) {
if (child instanceof PromptForCulture) {
await this.startChild(NumberPrompt, {
prompt: `What's your favorite number?`
}, child.return!.result.value!);
} else if (child instanceof NumberPrompt) {
await this.send(`${child.return!.result.value}? That's my favorite too!`);
await this.next();
}
}
}
FavoriteNumber.register();
// const wst = new WSTelemetry('ws://localhost:8080/server');
// Topic.telemetry = action => wst.send(action);
Topic.init(new MemoryStorage());
consoleOnTurn(
new ConsoleAdapter()
.use(prettyConsole),
context => doTopic(FavoriteNumber, context)
);