mirror of
https://github.com/arnaucube/commonroutesBot.git
synced 2026-02-27 21:06:39 +01:00
first commit
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
config.js
|
||||||
|
botimg.png
|
||||||
12
README.md
Normal file
12
README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# commonroutesBot
|
||||||
|
Telegram bot to notify when new travels are published.
|
||||||
|
|
||||||
|
|
||||||
|
### Common Routes repositories
|
||||||
|
- server code: https://github.com/arnaucube/commonroutesServer
|
||||||
|
- frontend app code: https://github.com/arnaucube/commonroutesApp
|
||||||
|
- frontend webapp code: https://github.com/arnaucube/commonroutesWebApp
|
||||||
|
- images server: https://github.com/arnaucube/goImgServer
|
||||||
|
- admin web: https://github.com/arnaucube/commonroutesAdminWeb
|
||||||
|
- landing page: https://github.com/arnaucube/commonroutesLandingPage
|
||||||
|
- telegram bot: https://github.com/arnaucube/commonroutesBot
|
||||||
4
configEXAMPLE.js
Normal file
4
configEXAMPLE.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
'telegramToken': 'tokenhere',
|
||||||
|
'port': 3003
|
||||||
|
};
|
||||||
79
main.js
Normal file
79
main.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
const TelegramBot = require('node-telegram-bot-api');
|
||||||
|
|
||||||
|
var express = require("express"),
|
||||||
|
app = express(),
|
||||||
|
bodyParser = require("body-parser"),
|
||||||
|
methodOverride = require("method-override");
|
||||||
|
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let chatId = ''; // only one chatid
|
||||||
|
|
||||||
|
const bot = new TelegramBot(config.telegramToken, {polling: true});
|
||||||
|
bot.onText(/\/start/, (msg, match) => {
|
||||||
|
console.log('chatId', chatId);
|
||||||
|
if(chatId) {
|
||||||
|
// only allow one chatId
|
||||||
|
} else {
|
||||||
|
chatId = msg.chat.id;
|
||||||
|
console.log('chatId', chatId);
|
||||||
|
var msg = `
|
||||||
|
Wellcome to commonroutesTelegramBot. Available commands:
|
||||||
|
/start
|
||||||
|
/pong
|
||||||
|
New messages will be send when new travels are published
|
||||||
|
`;
|
||||||
|
bot.sendMessage(chatId, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.onText(/\/ping/, (msg, match) => {
|
||||||
|
if(chatId) {
|
||||||
|
let msg = `pong
|
||||||
|
Bot alive.`;
|
||||||
|
bot.sendMessage(chatId, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var newtravelHandler = function(req, res) {
|
||||||
|
console.log(req.body);
|
||||||
|
let msg = `
|
||||||
|
New ` + req.body.type + ` travel published:
|
||||||
|
- 📣 title: ` + req.body.title + `
|
||||||
|
- 📄 description: ` + req.body.description + `
|
||||||
|
- 🌏 from: ` + req.body.from.name + `
|
||||||
|
- 🌍 to: ` + req.body.to.name + `
|
||||||
|
- 📆 date: ` + req.body.date + `
|
||||||
|
- 💺 seats: ` + req.body.seats;
|
||||||
|
if(req.body.package) {
|
||||||
|
msg += `
|
||||||
|
- 📦 can carry package`;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += `
|
||||||
|
|
||||||
|
📱 Check all the info in the app, or in the web visualizer https://routes.fair.coop/app/#!/travel/` + req.body._id + `
|
||||||
|
`;
|
||||||
|
bot.sendMessage(chatId, msg);
|
||||||
|
|
||||||
|
res.status(200).jsonp({});
|
||||||
|
}
|
||||||
|
|
||||||
|
// API
|
||||||
|
var apiRoutes = express.Router();
|
||||||
|
|
||||||
|
app.use(bodyParser.urlencoded({
|
||||||
|
extended: false
|
||||||
|
}));
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(methodOverride());
|
||||||
|
|
||||||
|
apiRoutes.route('/travel')
|
||||||
|
.post(newtravelHandler);
|
||||||
|
|
||||||
|
app.use('/api', apiRoutes);
|
||||||
|
app.listen(config.port, 'localhost', function() {
|
||||||
|
console.log("Node server running on http://localhost:" + config.port);
|
||||||
|
});
|
||||||
18
package.json
Normal file
18
package.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "commonroutesBot",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"prestart": "npm install",
|
||||||
|
"start": "node main.js"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "GPLv3",
|
||||||
|
"dependencies": {
|
||||||
|
"node-telegram-bot-api": "^0.30.0",
|
||||||
|
"express": "^4.7.1",
|
||||||
|
"method-override": "^2.1.2",
|
||||||
|
"body-parser": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user