Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected createEmulatorContext(session: ConversationReference): TurnContext {
// Get emulators adapter
const emulator = this.findAdapter('emulator');
if (!emulator) {
throw new Error(`BotDebugger: Cannot log debug activity to emulator. Adapter not found.`)
}
// Create request with session address
const request = TurnContext.applyConversationReference({
type: ActivityTypes.Event,
name: 'debuggerSession'
}, session);
// Return context for session
return new TurnContext(emulator, request);
}
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()); });
});
public continueConversation(reference: ConversationReference, logic: (context: TurnContext) => Promise): Promise {
// Create context and run middleware pipe
const activity: Partial = TurnContext.applyConversationReference({}, reference, true);
const context: TurnContext = new TurnContext(this, activity);
return this.runMiddleware(context, logic)
.catch((err: Error) => { this.printError(err.toString()); });
}
onReceive(activity) {
const context = new TurnContext(this, activity);
// Runs the middleware pipeline followed by any registered business logic.
// If no business logic has been registered via processActivity, a default
// value is provided as to not break the bot.
return this.runMiddleware(context, this.logic || function() { });
}
}
rl.on('line', (line) => {
// Initialize activity
const activity = botbuilder_core_1.TurnContext.applyConversationReference({
type: botbuilder_core_1.ActivityTypes.Message,
id: (this.nextId++).toString(),
timestamp: new Date(),
text: line
}, this.reference, true);
// Create context and run middleware pipe
const context = new botbuilder_core_1.TurnContext(this, activity);
this.runMiddleware(context, logic)
.catch((err) => { this.printError(err.toString()); });
});
return function close() {
continueConversation(reference, logic) {
// Create context and run middleware pipe
const activity = botbuilder_core_1.TurnContext.applyConversationReference({}, reference, true);
const context = new botbuilder_core_1.TurnContext(this, activity);
return this.runMiddleware(context, logic)
.catch((err) => { this.printError(err.toString()); });
}
/**
createContext(request) {
return new botbuilder_core_1.TurnContext(this, request);
}
}
protected createContext(request: Partial): TurnContext {
return new TurnContext(this as any, request);
}