Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createActivity(incoming, conversationId) {
return {
...incoming,
channelId: 'emulator',
serviceUrl: this.serviceUrl,
conversation: {
id: conversationId,
},
address: {
conversation: {
id: conversationId,
},
},
id: uuid(),
};
}
getConversation(id, autocreate = false) {
const conversationId = id || uuid();
if (!this.conversations[conversationId] && autocreate) {
this.conversations[conversationId] = {
conversationId,
history: [],
};
}
return this.conversations[conversationId];
}
return new Promise(resolve => {
const activity = srcActivity;
activity.id = uuid();
activity.from = {
id: process.env.BACKEND_ID || 'directline',
name: process.env.BACKEND_NAME || 'Directline',
};
const conversation = this.getConversation(conversationId, true);
conversation.history.push(activity);
resolve({
status: 200,
});
});
}
},
});
});
} else {
const result = {
type: 'message',
serviceUrl: activity.serviceUrl,
channelId: activity.channelId,
conversation: {
id: activity.conversation.id,
},
text: activity.text,
recipient: activity.from,
inputHint: 'acceptingInput',
replyToId: activity.id,
id: uuid(),
from: {
id: process.env.BACKEND_ID || 'directline',
name: process.env.BACKEND_NAME || 'Directline',
},
};
const nlp = this.settings.container.get('nlp');
if (nlp) {
nlp
.process({
message: activity.text,
channel: 'directline',
app: this.settings.container.name,
})
.then(nlpresult => {
result.text =
nlpresult.answer || "Sorry, I didn't understand you";