Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!activity.timestamp) {
activity.timestamp = new Date();
}
if (activity.type === 'delay') {
// The BotFrameworkAdapter and Console adapter implement this
// hack directly in the POST method. Replicating that here
// to keep the behavior as close as possible to facilitate
// more realistic tests.
// eslint-disable-next-line @typescript-eslint/tslint/config
const delayMs: number = activity.value;
await sleep(delayMs);
} else if (activity.type === ActivityTypes.Trace && activity.channelId !== 'emulator') {
// if it is a Trace activity we only send to the channel if it's the emulator.
} else if (activity.type === ActivityTypes.Typing && activity.channelId !== 'test') {
// If it's a typing activity we omit this in test scenarios to avoid test failures
} else {
// Queue up this activity for aggregation back to the calling Bot in one overall message.
this.queuedActivities.push(activity);
}
responses.push({ id: activity.id });
});
async () => {
if (!finished) {
let typingActivity: Partial = {
type: ActivityTypes.Typing,
relatesTo: context.activity.relatesTo
};
// Sending the Activity directly via the Adapter avoids other middleware and avoids setting the
// responded flag. However this also requires that the conversation reference details are explicitly added.
const conversationReference: Partial =
TurnContext.getConversationReference(context.activity);
typingActivity = TurnContext.applyConversationReference(typingActivity, conversationReference);
await context.adapter.sendActivities(context, [typingActivity]);
// Pass in period as the delay to repeat at an interval.
startInterval(context, period, period);
} else {
// Do nothing! This turn is done and we don't want to continue sending typing indicators.
}
if (text.length > 0) {
currentActivity.text = text;
currentActivity.timestamp = getIncrementedDate(delay);
newActivities.push(currentActivity);
// reset
delay = messageTimeGap;
currentActivity = createActivity({
type: ActivityTypes.Message,
from: parserModel.from,
recipient: parserModel.recipient,
conversationId: parserModel.conversation.id
});
currentActivity.text = '';
}
aggregate = aggregate.substr(result.index);
if (type === ActivityTypes.Typing) {
let newActivity = createActivity({
type,
recipient: parserModel.recipient,
from: parserModel.from,
conversationId: parserModel.conversation.id
});
newActivity.timestamp = getIncrementedDate(100);
newActivities.push(newActivity);
} else if (type === ActivityTypes.ConversationUpdate) {
processConversationUpdate(parserModel, newActivities, unparsedSource);
}
} else if (instruction && instruction === Instructions.Delay) {
delay = ~~rest;
} else if (field) {
// As more activity fields are supported,
// this should become a util or helper class.