kykint

Store keys in a separate config file

...@@ -88,4 +88,7 @@ typings/ ...@@ -88,4 +88,7 @@ typings/
88 # DynamoDB Local files 88 # DynamoDB Local files
89 .dynamodb/ 89 .dynamodb/
90 90
91 +# Config file
92 +config.js
93 +
91 # End of https://www.gitignore.io/api/node 94 # End of https://www.gitignore.io/api/node
......
1 const TelegramBot = require('node-telegram-bot-api'); 1 const TelegramBot = require('node-telegram-bot-api');
2 2
3 -// replace the value below with the Telegram token you receive from @BotFather 3 +const config = require('./config');
4 -const token = '825631426:AAE9tgw89kOZyLTre8DSDaObFQeVx7q41gw';
5 4
6 // Create a bot that uses 'polling' to fetch new updates 5 // Create a bot that uses 'polling' to fetch new updates
7 -const bot = new TelegramBot(token, { polling: true }); 6 +const bot = new TelegramBot(config.telegram.token, { polling: true });
8 7
9 var request = require('request'); 8 var request = require('request');
10 9
...@@ -14,10 +13,6 @@ const translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt'; ...@@ -14,10 +13,6 @@ const translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt';
14 // Language detection api url 13 // Language detection api url
15 const languagedetect_api_url = 'https://openapi.naver.com/v1/papago/detectLangs' 14 const languagedetect_api_url = 'https://openapi.naver.com/v1/papago/detectLangs'
16 15
17 -// Naver papago client id & secret
18 -const papago_client_id = 'lA0rGxQllAfrlOkGGNnK';
19 -const papago_client_secret = 'u3fykDlNb0';
20 -
21 // /echo [whatever] 16 // /echo [whatever]
22 bot.onText(/\/echo (.+)/, (msg, match) => { 17 bot.onText(/\/echo (.+)/, (msg, match) => {
23 // 'msg' is the received Message from Telegram 18 // 'msg' is the received Message from Telegram
...@@ -43,8 +38,8 @@ function translate(message, chatId) { ...@@ -43,8 +38,8 @@ function translate(message, chatId) {
43 url: languagedetect_api_url, 38 url: languagedetect_api_url,
44 form: { 'query': message }, 39 form: { 'query': message },
45 headers: { 40 headers: {
46 - 'X-Naver-Client-Id': papago_client_id, 41 + 'X-Naver-Client-Id': config.papago.client_id,
47 - 'X-Naver-Client-Secret': papago_client_secret 42 + 'X-Naver-Client-Secret': config.papago.client_secret
48 } 43 }
49 }; 44 };
50 45
...@@ -75,8 +70,8 @@ function translate(message, chatId) { ...@@ -75,8 +70,8 @@ function translate(message, chatId) {
75 'text': message // Message to translate 70 'text': message // Message to translate
76 }, 71 },
77 headers: { 72 headers: {
78 - 'X-Naver-Client-Id': papago_client_id, 73 + 'X-Naver-Client-Id': config.papago.client_id,
79 - 'X-Naver-Client-Secret': papago_client_secret 74 + 'X-Naver-Client-Secret': config.papago.client_secret
80 } 75 }
81 }; 76 };
82 77
......
1 +// Make a copy of this file, rename it to config.js
2 +// and fill in the following fields with your keys.
3 +module.exports = {
4 + telegram: {
5 + // Telegram token received from @BotFather
6 + token: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
7 + },
8 + papago: {
9 + // Naver papago client id & secret
10 + // https://developers.naver.com/apps/#/register
11 + client_id: 'XXXXXXXXXXXXXXXXXXXX',
12 + client_secret: 'XXXXXXXXXX'
13 + }
14 +}