-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinline_query.js
44 lines (37 loc) · 1.34 KB
/
inline_query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require('dotenv').config();
const axios = require('axios');
const { correctGrammar } = require('./helpers');
async function handleInlineContent(bot, query) {
const userText = query.query;
if (!userText) return;
try {
const response = await axios.get(`${process.env.TRANSLATE_API_URL}?q=${encodeURIComponent(userText)}&target=am`);
const translatedText = decodeURIComponent(response.data.translatedText);
const correctedText = await correctGrammar(userText);
bot.answerInlineQuery(query.id, [
{
type: 'article',
id: '1',
title: 'Amharic Translation',
description: `${translatedText}`,
input_message_content: {
message_text: `${translatedText}`,
parse_mode: 'HTML'
}
},
{
type: 'article',
id: '2',
title: 'Corrected Grammar',
description: `${correctedText}`,
input_message_content: {
message_text: `${correctedText}`,
parse_mode: 'HTML'
}
}
]);
} catch (error) {
console.error('Error in inline translation:', error);
}
}
module.exports = { handleInlineContent };