Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
id: message.user
},
recipient: {
id: 'bot'
},
channelData: message,
text: message.text,
type: message.type === 'message' ? ActivityTypes.Message : ActivityTypes.Event
};
// set botkit's event type
if (activity.type !== ActivityTypes.Message) {
activity.channelData.botkitEventType = message.type;
}
const context = new TurnContext(this, activity as Activity);
this.runMiddleware(context, logic)
.catch((err) => { console.error(err.toString()); });
} catch (e) {
var alert = [
`Error parsing incoming message from websocket.`,
`Message must be JSON, and should be in the format documented here:`,
`https://botkit.ai/docs/readme-web.html#message-objects`
];
console.error(alert.join('\n'));
console.error(e);
}
});
};
activity.recipient.id = await this.getBotUserByTeam(activity as Activity);
// Normalize the location of the team id
activity.channelData.team = event.team_id;
// add the team id to the conversation record
// @ts-ignore -- Tell Typescript to ignore this overload
activity.conversation.team = activity.channelData.team;
activity.channelData.botkitEventType = 'slash_command';
// create a conversation reference
// @ts-ignore
const context = new TurnContext(this, activity as Activity);
context.turnState.set('httpStatus', 200);
await this.runMiddleware(context, logic);
// send http response back
res.status(context.turnState.get('httpStatus'));
if (context.turnState.get('httpBody')) {
res.send(context.turnState.get('httpBody'));
} else {
res.end();
}
}
} else {
console.error('Unknown Slack event type: ', event);
}
public async continueConversation (
ref: ConversationReference,
callback: (context: TurnContext) => Promise,
): Promise {
const activity: Partial = TurnContext.applyConversationReference({}, ref, true)
try {
await this.runMiddleware(
new TurnContext(this, activity),
callback,
)
} catch (err) {
// TODO: add some code to deal with err...
throw err
}
}
activity.type = ActivityTypes.Event;
activity.channelData.botkitEventType = event.space.type === 'ROOM' ? 'bot_room_join' : 'bot_dm_join';
}
if (event.type === 'REMOVED_FROM_SPACE') {
activity.type = ActivityTypes.Event;
activity.channelData.botkitEventType = event.space.type === 'ROOM' ? 'bot_room_leave' : 'bot_dm_leave';
}
if (event.type === 'CARD_CLICKED') {
activity.type = ActivityTypes.Event;
activity.channelData.botkitEventType = event.type.toLowerCase();
}
// create a conversation reference
const context = new TurnContext(this, activity);
if (event.type !== 'CARD_CLICKED') {
// send 200 status immediately, otherwise
// hangouts does not mark the incoming message as received
res.status(200);
res.end();
} else {
context.turnState.set('httpStatus', 200);
}
await this.runMiddleware(context, logic);
if (event.type === 'CARD_CLICKED') {
// send http response back
res.status(context.turnState.get('httpStatus'));
if (context.turnState.get('httpBody')) {
this.wechaty.on('message', async msg => {
log.verbose('WechatyAdapter', 'listen() wechaty.on(message) %s', msg)
const activity = await this.buildActivity(msg)
if (!activity) {
// should skip this message
log.verbose('WechatyAdapter', 'listen() wechaty.on(message) no activity')
return
}
try {
await this.runMiddleware(
new TurnContext(this, activity),
logic,
)
} catch (err) {
throw err
}
})
public async processActivity(activity: Activity, callback: BotCallbackHandler): Promise {
const messageIn: string = `SkillHttpBotAdapter: Received an incoming activity. Activity id: ${activity.id}`;
this.telemetryClient.trackTrace({
message: messageIn,
severityLevel: Severity.Information
});
// Process the Activity through the Middleware and the Bot, this will generate Activities which we need to send back.
const context: TurnContext = new TurnContext(this, activity);
await this.runMiddleware(context, callback);
const messageOut: string = `SkillHttpBotAdapter: Batching activities in the response. ReplyToId: ${activity.id}`;
this.telemetryClient.trackTrace({
message: messageOut,
severityLevel: Severity.Information
});
// Any Activity responses are now available (via SendActivitiesAsync) so we need to pass back for the response
return {
status: 200,
body: this.queuedActivities.splice(0, this.queuedActivities.length)
};
}
public async continueConversation(reference: Partial, logic: (context: TurnContext) => Promise): Promise {
const request = TurnContext.applyConversationReference(
{ type: 'event', name: 'continueConversation' },
reference,
true
);
const context = new TurnContext(this, request);
return this.runMiddleware(context, logic);
}
public async continueConversation(
reference: Partial,
logic: (revocableContext: TurnContext) => Promise): Promise {
if (reference === undefined) {
throw new Error('Missing parameter. reference is required');
}
if (logic === undefined) {
throw new Error('Missing parameter. logic is required');
}
const context: TurnContext = new TurnContext(this, ActivityExtensions.getContinuationActivity(reference));
await this.runMiddleware(context, logic);
}
public async continueConversation(reference: Partial, logic: (context: TurnContext) => Promise): Promise {
const request = TurnContext.applyConversationReference(
{ type: 'event', name: 'continueConversation' },
reference,
true
);
const context = new TurnContext(this, request);
return this.runMiddleware(context, logic);
}
return __awaiter(this, void 0, void 0, function* () {
const request = botbuilder_1.TurnContext.applyConversationReference({ type: 'event', name: 'continueConversation' }, reference, true);
const context = new botbuilder_1.TurnContext(this, request);
return this.runMiddleware(context, logic);
});
}