Toggle navigation
Toggle navigation
This project
Loading...
Sign in
kykint
/
TELEGRAMBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
kykint
2019-06-02 16:49:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b004467b969e395c7eeb90fb483e3add6bc7dd61
b004467b
1 parent
f8f1da77
Store keys in a separate config file
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
11 deletions
.gitignore
app.js
config-sample.js
.gitignore
View file @
b004467
...
...
@@ -88,4 +88,7 @@ typings/
# DynamoDB Local files
.dynamodb/
# Config file
config.js
# End of https://www.gitignore.io/api/node
...
...
app.js
View file @
b004467
const
TelegramBot
=
require
(
'node-telegram-bot-api'
);
// replace the value below with the Telegram token you receive from @BotFather
const
token
=
'825631426:AAE9tgw89kOZyLTre8DSDaObFQeVx7q41gw'
;
const
config
=
require
(
'./config'
);
// Create a bot that uses 'polling' to fetch new updates
const
bot
=
new
TelegramBot
(
token
,
{
polling
:
true
});
const
bot
=
new
TelegramBot
(
config
.
telegram
.
token
,
{
polling
:
true
});
var
request
=
require
(
'request'
);
...
...
@@ -14,10 +13,6 @@ const translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt';
// Language detection api url
const
languagedetect_api_url
=
'https://openapi.naver.com/v1/papago/detectLangs'
// Naver papago client id & secret
const
papago_client_id
=
'lA0rGxQllAfrlOkGGNnK'
;
const
papago_client_secret
=
'u3fykDlNb0'
;
// /echo [whatever]
bot
.
onText
(
/
\/
echo
(
.+
)
/
,
(
msg
,
match
)
=>
{
// 'msg' is the received Message from Telegram
...
...
@@ -43,8 +38,8 @@ function translate(message, chatId) {
url
:
languagedetect_api_url
,
form
:
{
'query'
:
message
},
headers
:
{
'X-Naver-Client-Id'
:
papago_
client_id
,
'X-Naver-Client-Secret'
:
papago_
client_secret
'X-Naver-Client-Id'
:
config
.
papago
.
client_id
,
'X-Naver-Client-Secret'
:
config
.
papago
.
client_secret
}
};
...
...
@@ -75,8 +70,8 @@ function translate(message, chatId) {
'text'
:
message
// Message to translate
},
headers
:
{
'X-Naver-Client-Id'
:
papago_
client_id
,
'X-Naver-Client-Secret'
:
papago_
client_secret
'X-Naver-Client-Id'
:
config
.
papago
.
client_id
,
'X-Naver-Client-Secret'
:
config
.
papago
.
client_secret
}
};
...
...
config-sample.js
0 → 100644
View file @
b004467
// Make a copy of this file, rename it to config.js
// and fill in the following fields with your keys.
module
.
exports
=
{
telegram
:
{
// Telegram token received from @BotFather
token
:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
},
papago
:
{
// Naver papago client id & secret
// https://developers.naver.com/apps/#/register
client_id
:
'XXXXXXXXXXXXXXXXXXXX'
,
client_secret
:
'XXXXXXXXXX'
}
}
Please
register
or
login
to post a comment