kykint

Add language selection with '/l(anguage)' command

WIP. Needs a way to save user's choice.

Usage: /l or /language

- Let user select the language he wants his message to translate to.
  When triggered, bot will send an inline keyboard message with a list
  of available langauges. For an example of an inline keyboard message,
  see https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating.
Showing 1 changed file with 65 additions and 0 deletions
......@@ -137,3 +137,68 @@ bot.onText(/^\/(t|translate)($| ((.|\n)+))/, (msg, match) => {
translate(received_msg, chatId);
}
});
// /l(anguage)
// Let user select the language he wants his message to translate to.
// When triggered, bot will send an inline keyboard message with a list
// of available langauges. For an example of an inline keyboard message,
// see https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating.
bot.onText(/^\/(l|anguage)/, (msg, match) => {
const chatId = msg.chat.id;
const msgId = msg.message_id;
const inlineKeyboard = {
inline_keyboard: [
// Languages supported by papago language detection
// One array per line
[
{ text: '한국어', callback_data: 'ko' },
{ text: '영어', callback_data: 'en' },
{ text: '일본어', callback_data: 'ja' }
],
[
{ text: '중국어 간체', callback_data: 'zh-cn' },
{ text: '중국어 번체', callback_data: 'zh-tw' }
],
[
{ text: '힌디어', callback_data: 'hi' },
{ text: '스페인어', callback_data: 'es' },
{ text: '프랑스어', callback_data: 'fr' }
],
[
{ text: '독일어', callback_data: 'de' },
{ text: '포루트갈어', callback_data: 'pt' },
{ text: '베트남어', callback_data: 'vi' }
],
[
{ text: '인도네시아어', callback_data: 'id' },
{ text: '페르시아어', callback_data: 'fa' }
],
[
{ text: '아랍어', callback_data: 'ar' },
{ text: '미얀마어', callback_data: 'mm' },
{ text: '태국어', callback_data: 'th' }
],
[
{ text: '러시아어', callback_data: 'ru' },
{ text: '이탈리아어', callback_data: 'it' }
],
]
}
const options = {
reply_to_message_id: msgId,
reply_markup: inlineKeyboard
}
bot.sendMessage(chatId, '무슨 언어로 번역할까요? 선택은 기억됩니다.', options);
});
bot.on('callback_query', (query) => {
const data = query.data;
const options = {
text: 'From now on, your messages will be translated into ' + data
}
bot.answerCallbackQuery(query.id, options);
});
......