-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathknockKnock.ts
56 lines (41 loc) · 1.26 KB
/
knockKnock.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, prettyConsole, Waterfall, consoleOnTurn, doTopic } from '../src/topical';
class KnockKnock extends Waterfall {
waterfall() {
return [
() => this.send(`Who's there?`),
() => this.send(`${this.text} who?`),
() => this.send(`Hilarious!`),
];
}
// uses default onStart, onDispatch, onChildEnd
}
KnockKnock.register();
class Root extends Topic {
async onStart () {
await this.send(`Tell me a knock knock joke`);
}
async onDispatch () {
if (!this.text)
return;
if (this.text === 'knock knock') {
await this.startChild(KnockKnock);
return;
}
if (await this.dispatchToChild())
return;
await this.send(`Please, just one knock knock joke is all I ask.`)
}
async onChildEnd (child: KnockKnock) {
await this.send(`That was fun. Tell me another.`);
}
}
Root.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(Root, context)
);