Commit 7a736b47 authored by TJ Horner's avatar TJ Horner

yes

parents
BOT_TOKEN=
\ No newline at end of file
node_modules
config.json
.env
\ No newline at end of file
FROM node:carbon
WORKDIR /bot
COPY package*.json ./
RUN npm install
COPY . .
RUN [ "node", "index" ]
\ No newline at end of file
{
"BOT_TOKEN": "Telegram bot token",
"DEBUG": true
}
\ No newline at end of file
const mongoose = require('mongoose')
mongoose.connect(process.env.DB_URL || "mongodb://db")
const User = mongoose.model("User", {
telegramId: {
type: Number,
required: true,
unique: true
},
firstName: String,
lastName: String,
username: String
})
module.exports = { User }
\ No newline at end of file
version: '3'
services:
bot:
build: .
restart: unless-stopped
depends_on:
- db
environment:
DB_URL: mongodb://db
env_file: .env
db:
image: mongo:3.2.20-jessie
restart: unless-stopped
volumes:
- db:/data/db
volumes:
db:
\ No newline at end of file
var config
try {
config = require('./config.json')
} catch(e) {
config = process.env
}
const { User } = require('./db')
const Telegram = require('telegraf')
const bot = new Telegram(config.BOT_TOKEN)
bot.use((ctx, next) => {
User.find({ telegramId: ctx.from.id })
.catch(err => {
ctx.reply("An internal error occurred while processing your message, sorry! Please let @bcrypt know.")
})
.then(users => {
if(users.length) {
ctx.user = users[0]
next(ctx)
} else {
return User.create({
telegramId: ctx.from.id,
firstName: ctx.from.first_name,
lastName: ctx.from.last_name,
username: ctx.from.username
})
}
})
.catch(err => {
ctx.reply("An internal error occurred while processing your message, sorry! Please let @bcrypt know.")
})
.then(user => {
ctx.user = user
next(ctx)
})
})
if(config.DEBUG) {
bot.use((ctx, next) => {
console.log("[DEBUG]", ctx)
next(ctx)
})
}
bot.start(ctx => {
ctx.reply("Start command response")
})
bot.help(ctx => {
ctx.reply("Help command response")
})
bot.startPolling()
\ No newline at end of file
{
"name": "telegram-bot-boilerplate",
"version": "1.0.0",
"lockfileVersion": 1,
"dependencies": {
"@types/node": {
"version": "10.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz",
"integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q=="
},
"async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ=="
},
"bluebird": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz",
"integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw="
},
"bson": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.0.9.tgz",
"integrity": "sha512-IQX9/h7WdMBIW/q/++tGd+emQr0XMdeZ6icnT/74Xk9fnabWn+gZgpE+9V+gujL3hhJOoNrnDVY7tWdzc7NUTg=="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="
},
"kareem": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.2.1.tgz",
"integrity": "sha512-xpDFy8OxkFM+vK6pXy6JmH92ibeEFUuDWzas5M9L7MzVmHW3jzwAHxodCPV/BYkf4A31bVDLyonrMfp9RXb/oA=="
},
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"mongodb": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.1.tgz",
"integrity": "sha512-GU9oWK4pi8PC7NyGiwjFMwZyMqwGWoMEMvM0LZh7UKW/FFAqgmZKjjriD+5MEOCDUJE2dtHX93/K5UtDxO0otg=="
},
"mongodb-core": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.0.tgz",
"integrity": "sha512-qRjG62Fu//CZhkgn0jA/k8jh5MhACIq8cOJUryH6sck87pgt+C222MSD02tsCq5zNo/B6ZFHtNodZ2qpf8E86g=="
},
"mongoose": {
"version": "5.2.4",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.2.4.tgz",
"integrity": "sha512-UeFc4+PXbX0laHaUhVule6c/E/1e9ESb07zIg2FQQK0G0Ocq5BmVhWIEw6Sl/ZuNfLhC08WnERXNfAGy+Mlsgg=="
},
"mongoose-legacy-pluralize": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",
"integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ=="
},
"mpath": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.4.1.tgz",
"integrity": "sha512-NNY/MpBkALb9jJmjpBlIi6GRoLveLUM0pJzgbp9vY9F7IQEb/HREC/nxrixechcQwd1NevOhJnWWV8QQQRE+OA=="
},
"mquery": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mquery/-/mquery-3.0.0.tgz",
"integrity": "sha512-WL1Lk8v4l8VFSSwN3yCzY9TXw+fKVYKn6f+w86TRzOLSE8k1yTgGaLBPUByJQi8VcLbOdnUneFV/y3Kv874pnQ==",
"dependencies": {
"sliced": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-0.0.5.tgz",
"integrity": "sha1-XtwETKTrb3gW1Qui/GPiXY/kcH8="
}
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"node-fetch": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
"integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U="
},
"regexp-clone": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz",
"integrity": "sha1-p8LgmJH9vzj7sQ03b7cwA+aKxYk="
},
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g=="
},
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
},
"sandwich-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/sandwich-stream/-/sandwich-stream-1.0.0.tgz",
"integrity": "sha1-eDDkV5e1kzKH8fmyj4cZB0ViYvI="
},
"saslprep": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.0.tgz",
"integrity": "sha512-5lvKUEQ7lAN5/vPl5d3k8FQeDbEamu9kizfATfLLWV5h6Mkh1xcieR1FSsJkcSRUk49lF2tAW8gzXWVwtwZVhw==",
"optional": true
},
"semver": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
"integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA=="
},
"sliced": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
},
"telegraf": {
"version": "3.21.2",
"resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.21.2.tgz",
"integrity": "sha512-hstPgYodQZuPN3yEZp1FRfeawz7yxrLx0C7KYYz4v4BPF53PnWYTpbwl4bg+VCRf0B/YIN1dYo/wZVQIxTWArw==",
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g=="
}
}
},
"telegram-typings": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/telegram-typings/-/telegram-typings-3.6.1.tgz",
"integrity": "sha512-njVv1EAhIZnmQVLocZEADYUyqA1WIXuVcDYlsp+mXua/XB0pxx+PKtMSPeZ/EE4wPWTw9h/hA9ASTT6yQelkiw=="
},
"typescript": {
"version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w=="
}
}
}
{
"name": "telegram-bot-boilerplate",
"version": "1.0.0",
"description": "Telegram bot boilerplate",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.horner.tj/tj/telegram-bot-boilerplate.git"
},
"author": "TJ Horner <me@tjhorner.com>",
"license": "GPL-3.0",
"dependencies": {
"mongoose": "^5.2.4",
"telegraf": "^3.21.2"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment