kykint

Store keys in a separate config file

......@@ -88,4 +88,7 @@ typings/
# DynamoDB Local files
.dynamodb/
# Config file
config.js
# End of https://www.gitignore.io/api/node
......
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
}
};
......
// 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'
}
}