Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function receive(node, config = {}, context) {
// Log activity
try {
setTimeout(function() {
helper.trackActivities(node);
}, 0);
} catch (err) {
console.log(err);
}
let data = buildMessageFlow(context.activity);
// Add context object to store the lifetime of the stream
let convId = botmgr.getConvId(data);
let ref = TurnContext.getConversationReference(context.activity);
let _context = botmgr.getContext(data);
_context.convRef = ref;
// Handle Prompt
if (botmgr.hasDelayedCallback(convId, data.message)) {
return;
}
// Send message
_context.lastMessageDate = data.message.timestamp;
helper.emitEvent("received", node, data, config);
node.send([null, data]);
}
async function endSkillConversation(context) {
try {
// Inform the active skill that the conversation is ended so that it has
// a chance to clean up.
// Note: ActiveSkillPropertyName is set by the RooBot while messages are being
// forwarded to a Skill.
const activeSkill = await conversationState.createProperty(RootBot.ActiveSkillPropertyName).get(context);
if (activeSkill) {
const botId = process.env.MicrosoftAppId;
let endOfConversation = {
type: ActivityTypes.EndOfConversation,
code: 'RootSkillError'
};
endOfConversation = TurnContext.applyConversationReference(
endOfConversation, TurnContext.getConversationReference(context.activity), true);
await conversationState.saveChanges(context, true);
await skillClient.postToSkill(botId, activeSkill, skillsConfig.skillHostEndpoint, endOfConversation);
}
} catch (err) {
console.error(`\n [onTurnError] Exception caught on attempting to send EndOfConversation : ${ err }`);
}
}
async createJob(turnContext) {
// Create a unique job ID.
var date = new Date();
var jobIdNumber = date.getTime();
// Get the conversation reference.
const reference = TurnContext.getConversationReference(turnContext.activity);
// Get the list of jobs. Default it to {} if it is empty.
const jobs = await this.jobsList.get(turnContext, {});
// Try to find previous information about the saved job.
const jobInfo = jobs[jobIdNumber];
try {
if (isEmpty(jobInfo)) {
// Job object is empty so we have to create it
await turnContext.sendActivity(`Need to create new job ID: ${ jobIdNumber }`);
// Update jobInfo with new info
jobs[jobIdNumber] = { completed: false, reference: reference };
try {
async createSkillConversationIdWithOptions(options) {
const skillConversationReference = {
conversationReference: TurnContext.getConversationReference(options.activity),
oAuthScope: options.fromBotOAuthScope
};
// This key has a 100 character limit by default. Increase with `restify.createServer({ maxParamLength: 1000 });` in index.js.
const key = `${ options.fromBotId }-${ options.botFrameworkSkill.appId }-${ skillConversationReference.conversationReference.conversation.id }-${ skillConversationReference.conversationReference.channelId }-skillconvo`;
this.refs[key] = skillConversationReference;
return key;
}
bot.onEvent(async (context, next) => {
const {
activity: { name, value }
} = context;
// Intercepts all "upload" event activities.
if (name === 'upload') {
// For async operations that are outside of BotBuilder, we should use proactive messaging.
const reference = TurnContext.getConversationReference(context.activity);
// The file upload validation could take more than a second, we should send a typing indicator.
await context.sendActivity({ type: 'typing' });
const { files } = value;
const pipeline = StorageURL.newPipeline(
new SharedKeyCredential(AZURE_STORAGE_ACCOUNT_NAME, AZURE_STORAGE_ACCOUNT_KEY)
);
const properties = await Promise.all(
files.map(file => {
// You should verify the URL if it is from the blob account and container that this service owned.
const blockBlobURL = new BlockBlobURL(file, pipeline);
// After the bot receives the URL, it should validate its content and associate it with the user ID.
public async spawn(config?: any): Promise {
if (config instanceof TurnContext) {
config = {
dialogContext: await this.dialogSet.createContext(config as TurnContext),
context: config as TurnContext,
reference: TurnContext.getConversationReference(config.activity),
activity: config.activity
};
} else if (config instanceof DialogContext) {
config = {
dialogContext: config,
reference: TurnContext.getConversationReference(config.context.activity),
context: config.context,
activity: config.context.activity
};
}
let worker: BotWorker = null;
if (this.adapter.botkit_worker) {
let CustomBotWorker = this.adapter.botkit_worker;
worker = new CustomBotWorker(this, config);
} else {
async function sendWelcomeMessage(node, context, resolve, reject, next) {
let data = buildMessageFlow(context.activity);
data.message = {};
let ref = TurnContext.getConversationReference(context.activity);
let _context = botmgr.getContext(data);
_context.convRef = ref;
_context.next = next;
resolve();
node.send([data, null]);
}
public async spawn(config?: any): Promise {
if (config instanceof TurnContext) {
config = {
dialogContext: await this.dialogSet.createContext(config as TurnContext),
context: config as TurnContext,
reference: TurnContext.getConversationReference(config.activity),
activity: config.activity
};
} else if (config instanceof DialogContext) {
config = {
dialogContext: config,
reference: TurnContext.getConversationReference(config.context.activity),
context: config.context,
activity: config.context.activity
};
}
let worker: BotWorker = null;
if (this.adapter.botkit_worker) {
let CustomBotWorker = this.adapter.botkit_worker;
worker = new CustomBotWorker(this, config);
} else {
worker = new BotWorker(this, config);
}
return new Promise((resolve, reject) => {
this.middleware.spawn.run(worker, (err, worker) => {
if (err) {
async (t1) => {
const ref2 = TurnContext.getConversationReference(t1.activity);
await t1.adapter.continueConversation(ref2, async (t2) => {
await t2.sendActivity(message);
});
});
});
public async onTurn(context: TurnContext, next: () => Promise): Promise {
const activity: Activity = context.activity;
const fromRole: string = activity.from.role ? activity.from.role.toLowerCase() : '';
if (fromRole === 'user') {
const proactiveState: ProactiveModel = await this.proactiveStateAccessor.get(context, new ProactiveModel());
let data: ProactiveData;
const hashedUserId: string = MD5Util.computeHash(activity.from.id);
const conversationReference: Partial = TurnContext.getConversationReference(activity);
if (proactiveState[hashedUserId] !== undefined) {
data = { conversation: conversationReference };
proactiveState[hashedUserId] = { conversation: conversationReference };
} else {
data = { conversation: conversationReference };
}
proactiveState[hashedUserId] = data;
await this.proactiveStateAccessor.set(context, proactiveState);
await this.proactiveState.saveChanges(context);
}
await next();
}
}