Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rl.on('line', (line: string) => {
// Initialize activity
const activity: Partial = TurnContext.applyConversationReference(
{
id: (this.nextId++).toString(),
text: line,
timestamp: new Date(),
type: ActivityTypes.Message
},
this.reference,
true
);
// Create context and run middleware pipe
const context: TurnContext = new TurnContext(this, activity);
this.runMiddleware(context, logic)
.catch((err: Error) => { this.printError(err.toString()); });
});
// Validate the return value
// - Unlike the other prompts a validator is required for an ActivityPrompt so we don't
// need to check for its existence before calling it.
const isValid: boolean = await this.validator({
context: dc.context,
recognized: recognized,
state: state.state,
options: state.options,
attemptCount: ++state.state['attemptCount']
});
// Return recognized value or re-prompt
if (isValid) {
return await dc.endDialog(recognized.value);
} else {
if (dc.context.activity.type === ActivityTypes.Message && !dc.context.responded) {
await this.onPrompt(dc.context, state.state, state.options, true);
}
return Dialog.EndOfTurn;
}
}
}
// Perform default processing
if (preBubble) {
switch (event.name) {
case AdaptiveEventNames.beginDialog:
const activityReceivedEvent: DialogEvent = {
name: AdaptiveEventNames.activityReceived,
value: sequence.context.activity,
bubble: false
}
handled = await this.processEvent(sequence, activityReceivedEvent, true);
break;
case AdaptiveEventNames.activityReceived:
const activity = sequence.context.activity;
if (activity.type === ActivityTypes.Message) {
// Recognize utterance
const recognizeUtteranceEvent: DialogEvent = {
name: AdaptiveEventNames.recognizeUtterance,
value: sequence.context.activity,
bubble: false
};
await this.processEvent(sequence, recognizeUtteranceEvent, true);
const recognized = sequence.state.getValue('turn.recognized').value;
const recognizedIntentEvent: DialogEvent = {
name: AdaptiveEventNames.recognizedIntent,
value: recognized,
bubble: false
}
handled = await this.processEvent(sequence, recognizedIntentEvent, true);
}
break;
}
} else {
switch (event.name) {
case AdaptiveEventNames.beginDialog:
const activityReceivedEvent: DialogEvent = {
name: AdaptiveEventNames.activityReceived,
value: sequence.context.activity,
bubble: false
};
// Emit trailing ActivityReceived event
handled = await this.processEvent(sequence, activityReceivedEvent, false);
break;
case AdaptiveEventNames.activityReceived:
const activity = sequence.context.activity;
if (activity.type === ActivityTypes.Message) {
// Do we have an empty sequence?
if (sequence.actions.length == 0) {
const unknownIntentEvent: DialogEvent = {
name: AdaptiveEventNames.unknownIntent,
bubble: false
};
// Emit trailing UnknownIntent event
handled = await this.processEvent(sequence, unknownIntentEvent, false);
} else {
handled = false;
}
}
if (handled) {
sequence.state.setValue('turn.interrupted', true);
}
activities.forEach((activity) => {
if (activity.type == ActivityTypes.Message) {
this._logger.log(`Bot: Text = ${ activity.text }`);
this._logger.log(` Speak = ${ activity.speak }`);
this._logger.log(` InputHint = ${ activity.inputHint }`);
} else {
this._logger.log(`Bot: Activity = ${ activity.type }`);
JSON.stringify(activity,null,2).split(/\n/).forEach((line) =>{ this._logger.log(line); });
}
});
let now = new Date();
public async continueDialog(dc: DialogContext): Promise {
const activity = dc.context.activity;
if (activity.type === ActivityTypes.Message) {
return await dc.endDialog();
} else {
return Dialog.EndOfTurn;
}
}
}
token = context.activity.value as TokenResponse;
} else if (this.isTeamsVerificationInvoke(context)) {
const code: any = context.activity.value.state;
try {
token = await this.getUserToken(context, code);
if (token !== undefined) {
await context.sendActivity({ type: 'invokeResponse', value: { status: 200 }});
} else {
await context.sendActivity({ type: 'invokeResponse', value: { status: 404 }});
}
}
catch (e)
{
await context.sendActivity({ type: 'invokeResponse', value: { status: 500 }});
}
} else if (context.activity.type === ActivityTypes.Message) {
const matched: RegExpExecArray = /(\d{6})/.exec(context.activity.text);
if (matched && matched.length > 1) {
token = await this.getUserToken(context, matched[1]);
}
}
return token !== undefined ? { succeeded: true, value: token } : { succeeded: false };
}
constructor(actions: Dialog[] = [], condition?: string) {
super(ActivityTypes.Message, actions, condition);
}
}
public set value(value: Partial|string) {
this._value = value;
this._textTemplate = undefined;
if (typeof value === 'string') {
this._textTemplate = stringTemplate.compile(value);
} else if (typeof value === 'object' && value.type === ActivityTypes.Message) {
this._textTemplate = stringTemplate.compile(value.text);
}
}
processor: async (dc) => {
const activity = dc.context.activity;
if (activity.type === ActivityTypes.Message) {
return await dc.endDialog(activity.text || '');
} else {
return Dialog.EndOfTurn;
}
}
};