-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.ts
More file actions
54 lines (45 loc) · 1.81 KB
/
bot.ts
File metadata and controls
54 lines (45 loc) · 1.81 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
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { TurnContext } from 'botbuilder'
import { StorageLayerType } from '../../src'
import * as wolf from 'wolf-core'
import { abilities } from './abilities'
import { slots } from './slots'
import nlp from './nlp'
export interface ConversationData {
name?: string
}
const flow: wolf.Flow<ConversationData, StorageLayerType<ConversationData>> = {
abilities,
slots
}
export class MyBot {
private wolfStorageLayer: wolf.StorageLayerFactory<TurnContext, wolf.WolfState, StorageLayerType<wolf.WolfState>>
private conversationStorageLayer: wolf.StorageLayerFactory<TurnContext, ConversationData, StorageLayerType<ConversationData>>
constructor(
wolfStorageLayer: wolf.StorageLayerFactory<TurnContext, wolf.WolfState, StorageLayerType<wolf.WolfState>>,
conversationStorageLayer: wolf.StorageLayerFactory<TurnContext, ConversationData, StorageLayerType<ConversationData>>
) {
this.wolfStorageLayer = wolfStorageLayer
this.conversationStorageLayer = conversationStorageLayer
}
/**
* Use onTurn to handle an incoming activity, received from a user, process it, and reply as needed
*
* @param {TurnContext} turnContext context object.
*/
public onTurn = async (turnContext: TurnContext) => {
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
// Bot logic here
const wolfResult = await wolf.run(
this.wolfStorageLayer(turnContext),
this.conversationStorageLayer(turnContext, {}),
() => nlp(turnContext),
() => flow,
'echo'
)
// Respond Wolf messages
const sendActivities = wolfResult.messageStringArray.map((message) => turnContext.sendActivity(message))
await Promise.all(sendActivities)
}
}