-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (47 loc) · 1.74 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint no-console: 0 */
const TelegramBot = require('node-telegram-bot-api');
const config = require('./config');
// moedoo returns a curry function
const moedoo = require('./lib/moedoo')(process.env.DATABASE_URL || {
DB_USER: config.DB_USER,
DB_PASSWORD: config.DB_PASSWORD,
DB_HOST: config.DB_HOST,
DB_PORT: config.DB_PORT,
DB_NAME: config.DB_NAME,
});
const message = require('./responders/message');
const callbackQuery = require('./responders/callback');
const TOKEN = process.env.TELEGRAM_TOKEN;
const options = {
webHook: {
port: process.env.PORT,
},
};
const bot = new TelegramBot(TOKEN, options);
const url = process.env.APP_URL || 'https://nooice.herokuapp.com:443';
bot.setWebHook(`${url}/bot${TOKEN}`);
bot.on('message', message(bot, config, moedoo));
bot.on('callback_query', callbackQuery(bot, config, moedoo));
moedoo.query(`
-- CREATE EXTENSION postgis;
-- DROP TABLE atm; -- flush
CREATE TABLE IF NOT EXISTS atm (
atm_id serial NOT NULL,
atm_location geometry, -- locaton
atm_bank_name character varying(128) DEFAULT 'ATM'::character varying, -- bank
atm_timestamp timestamp with time zone DEFAULT now(), -- creation timestamp
atm_approved boolean DEFAULT false, -- approval status
CONSTRAINT atm_pk PRIMARY KEY (atm_id)
);
CREATE TABLE IF NOT EXISTS nooice (
nooice_id serial NOT NULL, -- telegram user_id will be used as PK
CONSTRAINT nooice_id PRIMARY KEY (nooice_id)
);
-- test data
-- INSERT INTO atm (atm_location, atm_bank_name, atm_approved) VALUES (ST_GeomFromGeoJSON('{"type": "point", "coordinates": [9.0199, 38.7969]}'), 'Commercial Bank of Ethiopia', true);
`)
.then(() => {
console.log('NOOICE! - DB READY');
}, (err) => {
console.log('NOOICE 😔', err);
});