Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve telegram integration #840

Merged
merged 6 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ coverage
# VSCode
.vscode
.tmp
.DS_Store
4 changes: 4 additions & 0 deletions server/services/telegram/lib/message.linkUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ async function linkUser(apiKey, chatId) {
telegram_user_id: chatId,
});
logger.debug(`Telegram user linked with success.`);
// sending message to confirm
await this.send(chatId, {
text: '👋',
});
}

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion server/services/telegram/lib/message.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ const { EVENTS } = require('../../../utils/constants');
async function newMessage(msg) {
logger.debug(`new message from telegram, ${msg.text}`);
logger.debug(msg);

const telegramUserId = msg.from.id;
const telegramChatId = msg.chat.id;

if (msg.text.startsWith('/start')) {
const splitted = msg.text.split(' ');
await this.linkUser(splitted[1], telegramUserId);
return null;
}

const user = await this.gladys.user.getByTelegramUserId(telegramUserId);

const message = {
source: 'telegram',
source_user_id: telegramUserId,
source_user_id: telegramChatId,
user_id: user.id,
user,
language: user.language,
Expand Down
6 changes: 6 additions & 0 deletions server/test/services/telegram/lib/messageHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('Telegram.message', () => {
from: {
id: '89798374Z7',
},
chat: {
id: '89798374Z7',
},
text: 'Hey',
date: new Date(),
});
Expand All @@ -44,6 +47,9 @@ describe('Telegram.message', () => {
from: {
id: '89798374Z7',
},
chat: {
id: '89798374Z7',
},
text: '/start testapikey',
date: new Date(),
});
Expand Down