Skip to content

Commit 4c76326

Browse files
committed
Added telegram variables for chat.
1 parent 9525ad6 commit 4c76326

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

server/mongo/direct/generateResponse.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ const Analytics = require('../schemas/analyticsSchema');
2323
* @param model - Which model within the agent should we target.
2424
* @param talkWrapper - Which talk group should we target.
2525
*/
26-
function generateResponseInternal(uid, message, project, model, talkWrapper) {
26+
function generateResponseInternal(
27+
uid,
28+
message,
29+
project,
30+
model,
31+
talkWrapper,
32+
sessionEntities = {},
33+
) {
2734
return new Promise(resolve =>
2835
co(function* t() {
2936
try {
@@ -36,6 +43,10 @@ function generateResponseInternal(uid, message, project, model, talkWrapper) {
3643
parseInteral({ project, q: message, model }),
3744
Session.getSessionInternal(uid),
3845
];
46+
session.entities.saved = Object.assign(
47+
session.entities.saved,
48+
sessionEntities,
49+
);
3950
timer('Got Items');
4051
data.ruid = uuidv1();
4152

server/mongo/direct/traverseNodes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class TraverseNodes {
149149
const sessionEntities = this.session.entities.saved;
150150

151151
if (sessionEntities) {
152-
_.forEach(sessionEntities, ({ value }, key) => {
152+
_.forEach(sessionEntities, (data, key) => {
153+
const { value } = data;
153154
const replace = this.escapeRegExp(key);
154155
output = _.replace(output, new RegExp(replace, 'g'), value);
155156
});

server/thirdparties/telegramBot.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable camelcase */
22
const TelegramBot = require('node-telegram-bot-api');
3+
const forOwn = require('lodash/forOwn');
34
const {
45
generateResponseInternal,
56
} = require('../mongo/direct/generateResponse');
@@ -13,12 +14,17 @@ const telegramBot = props => {
1314
global.bot.setWebHook(`${domain_name}/bot/telegramAPI`);
1415
global.bot.on('message', msg => {
1516
const chatId = msg.chat.id;
17+
const telegramDetails = {};
18+
forOwn(msg.from, (value, key) => {
19+
telegramDetails[`t_${key}`] = { value };
20+
});
1621
generateResponseInternal(
1722
msg.chat.id,
1823
msg.text,
1924
global.bot.options.project,
2025
null,
2126
global.bot.options.talkWrapper,
27+
telegramDetails,
2228
).then(replies => {
2329
replies.forEach(reply => {
2430
global.bot.sendMessage(chatId, reply.text);

0 commit comments

Comments
 (0)