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) => { ...@@ -137,3 +137,68 @@ bot.onText(/^\/(t|translate)($| ((.|\n)+))/, (msg, match) => {
137 translate(received_msg, chatId); 137 translate(received_msg, chatId);
138 } 138 }
139 }); 139 });
140 +
141 +// /l(anguage)
142 +// Let user select the language he wants his message to translate to.
143 +// When triggered, bot will send an inline keyboard message with a list
144 +// of available langauges. For an example of an inline keyboard message,
145 +// see https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating.
146 +bot.onText(/^\/(l|anguage)/, (msg, match) => {
147 + const chatId = msg.chat.id;
148 + const msgId = msg.message_id;
149 +
150 + const inlineKeyboard = {
151 + inline_keyboard: [
152 + // Languages supported by papago language detection
153 + // One array per line
154 + [
155 + { text: '한국어', callback_data: 'ko' },
156 + { text: '영어', callback_data: 'en' },
157 + { text: '일본어', callback_data: 'ja' }
158 + ],
159 + [
160 + { text: '중국어 간체', callback_data: 'zh-cn' },
161 + { text: '중국어 번체', callback_data: 'zh-tw' }
162 + ],
163 + [
164 + { text: '힌디어', callback_data: 'hi' },
165 + { text: '스페인어', callback_data: 'es' },
166 + { text: '프랑스어', callback_data: 'fr' }
167 + ],
168 + [
169 + { text: '독일어', callback_data: 'de' },
170 + { text: '포루트갈어', callback_data: 'pt' },
171 + { text: '베트남어', callback_data: 'vi' }
172 + ],
173 + [
174 + { text: '인도네시아어', callback_data: 'id' },
175 + { text: '페르시아어', callback_data: 'fa' }
176 + ],
177 + [
178 + { text: '아랍어', callback_data: 'ar' },
179 + { text: '미얀마어', callback_data: 'mm' },
180 + { text: '태국어', callback_data: 'th' }
181 + ],
182 + [
183 + { text: '러시아어', callback_data: 'ru' },
184 + { text: '이탈리아어', callback_data: 'it' }
185 + ],
186 + ]
187 + }
188 + const options = {
189 + reply_to_message_id: msgId,
190 + reply_markup: inlineKeyboard
191 + }
192 +
193 + bot.sendMessage(chatId, '무슨 언어로 번역할까요? 선택은 기억됩니다.', options);
194 +});
195 +
196 +bot.on('callback_query', (query) => {
197 + const data = query.data;
198 +
199 + const options = {
200 + text: 'From now on, your messages will be translated into ' + data
201 + }
202 +
203 + bot.answerCallbackQuery(query.id, options);
204 +});
......