+ format / doc

master
io42630 3 years ago
parent 401cadf040
commit a20b5b9950

2
.gitignore vendored

@ -1,6 +1,6 @@
/.idea/ /.idea/
*keys.json *keys.json
/ree-bot-translate.iml /translate_reebot.iml
package-lock.json package-lock.json
/node_modules /node_modules
/dist /dist

@ -0,0 +1,10 @@
# Translate ReeBot
### About
* Uses DeepL for Telegram inline translations.
### How To
* enter API-keys into `keys-template.json`, then rename to `keys.json`.
* `npm run build / start`
* in Telegram : add bot > enable inline > /start > use via inline.

@ -0,0 +1,4 @@
{
"DEEPL": "",
"TRANSLATE_REEBOT": ""
}

@ -1,10 +1,10 @@
import TelegramBot from "node-telegram-bot-api"; import TelegramBot, { InlineQuery } from 'node-telegram-bot-api';
import { Options } from "request"; import { Options } from 'request';
const translate = require('./translate-adapter').translate const translate = require('./translate-adapter').translate;
const keys = require('../keys.json'); const keys = require('../keys.json');
let request_options: Options = { url: "" }; let request_options: Options = {url: ''};
let options: TelegramBot.ConstructorOptions = { let options: TelegramBot.ConstructorOptions = {
polling: true, polling: true,
@ -12,22 +12,19 @@ let options: TelegramBot.ConstructorOptions = {
}; };
const bot = new TelegramBot(keys.TRANSLATE_REEBOT, options); const bot = new TelegramBot(keys.TRANSLATE_REEBOT, options);
bot.on("inline_query", async msg => { bot.on('inline_query', async (msg: InlineQuery) => {
console.log(JSON.stringify(msg));
let results: Array<TelegramBot.InlineQueryResult> = [];
if (msg.query.length <= 1) return;
if (msg.query.length > 1) { if (msg.query.length > 1) {
let translated = await translate(msg.query, 'de'); const translated = (await translate(msg.query, 'de')).text;
results = [ const results: Array<TelegramBot.InlineQueryResult> = [
{ {
type: 'article', type: 'article',
id: 'hello_id', id: 'hello_id',
title: translated.text, title: translated,
input_message_content: { input_message_content: {
message_text: translated.text message_text: translated
} }
} }
]; ];
await bot.answerInlineQuery(msg.id, results);
} }
bot.answerInlineQuery(msg.id, results);
}); });

Loading…
Cancel
Save