commit
401cadf040
@ -0,0 +1,6 @@
|
|||||||
|
/.idea/
|
||||||
|
*keys.json
|
||||||
|
/ree-bot-translate.iml
|
||||||
|
package-lock.json
|
||||||
|
/node_modules
|
||||||
|
/dist
|
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "translate-reboot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"start": "npm run serve",
|
||||||
|
"serve": "node dist/bot-adapter.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.27.2",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
|
"deepl-node": "^1.3.1",
|
||||||
|
"node-telegram-bot-api": "^0.57.0",
|
||||||
|
"tsc": "^2.0.4",
|
||||||
|
"tslib": "^2.4.0",
|
||||||
|
"typescript": "^4.7.4",
|
||||||
|
"@types/node": "^18.0.0",
|
||||||
|
"@types/node-telegram-bot-api" : "^0.57.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import TelegramBot from "node-telegram-bot-api";
|
||||||
|
import { Options } from "request";
|
||||||
|
|
||||||
|
const translate = require('./translate-adapter').translate
|
||||||
|
const keys = require('../keys.json');
|
||||||
|
|
||||||
|
let request_options: Options = { url: "" };
|
||||||
|
|
||||||
|
let options: TelegramBot.ConstructorOptions = {
|
||||||
|
polling: true,
|
||||||
|
request: request_options
|
||||||
|
};
|
||||||
|
const bot = new TelegramBot(keys.TRANSLATE_REEBOT, options);
|
||||||
|
|
||||||
|
bot.on("inline_query", async msg => {
|
||||||
|
console.log(JSON.stringify(msg));
|
||||||
|
let results: Array<TelegramBot.InlineQueryResult> = [];
|
||||||
|
if (msg.query.length <= 1) return;
|
||||||
|
if (msg.query.length > 1) {
|
||||||
|
let translated = await translate(msg.query, 'de');
|
||||||
|
results = [
|
||||||
|
{
|
||||||
|
type: 'article',
|
||||||
|
id: 'hello_id',
|
||||||
|
title: translated.text,
|
||||||
|
input_message_content: {
|
||||||
|
message_text: translated.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
bot.answerInlineQuery(msg.id, results);
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
import { TextResult, Translator } from 'deepl-node';
|
||||||
|
|
||||||
|
const keys = require('../keys.json');
|
||||||
|
const translator = new Translator(keys.DEEPL);
|
||||||
|
|
||||||
|
export const translate: (a: String, b: String) => Promise<TextResult> =
|
||||||
|
(async (textToTranslate: any, lang: any) => {
|
||||||
|
return await translator.translateText(textToTranslate, null, lang);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"target": "es6",
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"*": [
|
||||||
|
"node_modules/*",
|
||||||
|
"src/types/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in new issue