-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b7a05f
Showing
12 changed files
with
2,814 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
}, | ||
"env": { | ||
"node": true, | ||
"jest": true, | ||
"es6": true, | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"prettier", | ||
], | ||
"plugins": [ | ||
"prettier", | ||
], | ||
"rules": { | ||
"prettier/prettier": ["error", { | ||
"trailingComma": "es5", | ||
"printWidth": 120, | ||
}], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Custom | ||
lib | ||
|
||
# Created by https://www.gitignore.io/api/node,osx,windows,linux | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
### OSX ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# End of https://www.gitignore.io/api/node,osx,windows,linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM node:8 | ||
|
||
# Configure timezone | ||
ENV TZ=America/Santiago | ||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | ||
|
||
# Create app directory | ||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
# Install app dependencies | ||
COPY package.json /usr/src/app/ | ||
RUN npm install | ||
|
||
# Bundle app source | ||
COPY . /usr/src/app | ||
|
||
EXPOSE 4000 | ||
|
||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Cryptowl Bot | ||
|
||
[![dependencies][dependencies-image]][dependencies-url] [![dev-dependencies][dev-dependencies-image]][dev-dependencies-url] [](https://github.com/prettier/prettier) | ||
|
||
Telegram bot built with [`telegraf/telegraf`](https://github.com/telegraf/telegraf). | ||
|
||
> [Start conversation here](https://t.me/cryptowl_bot) | ||
## Development | ||
|
||
**Requirements:** | ||
* Node.js 8 | ||
* Yarn | ||
|
||
Clone this repository: | ||
|
||
```sh | ||
git clone https://github.com/cryptowljs/cryptowl_bot.git | ||
cd cryptowl_bot | ||
``` | ||
|
||
Install dependencies: | ||
```sh | ||
yarn | ||
``` | ||
|
||
Make sure to set the next environment variables: | ||
|
||
```txt | ||
URL=https://asdfg.ngrok.io | ||
TELEGRAM__TOKEN=1g**********************VbQYF | ||
TELEGRAM__USERNAME=cryptowl_bot | ||
TELEGRAM__SECRET_PATH=aaaaaaaaaaaaaaaaaaaaa | ||
``` | ||
|
||
These can be set with a `.env` files (ignored by git). | ||
|
||
Start this bot: | ||
|
||
```sh | ||
yarn start | ||
``` | ||
|
||
## Production | ||
|
||
**Requirements:** | ||
* Docker | ||
* Docker-Compose | ||
|
||
Create the same `.env` file but with the production values. Then: | ||
|
||
```sh | ||
docker-compose up -d --build | ||
``` | ||
|
||
[dependencies-image]: https://david-dm.org/cryptowljs/cryptowl_bot.svg | ||
[dependencies-url]: https://david-dm.org/cryptowljs/cryptowl_bot | ||
[dev-dependencies-image]: https://david-dm.org/cryptowljs/cryptowl_bot/dev-status.svg | ||
[dev-dependencies-url]: https://david-dm.org/cryptowljs/cryptowl_bot#info=devDependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"NODE_ENV": "development", | ||
"PORT": 4000, | ||
"APP_URL": null, | ||
"NOW_URL": null, | ||
"URL": null, | ||
"TELEGRAM": { | ||
"TOKEN": null, | ||
"USERNAME": null, | ||
"SECRET_PATH": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '2' | ||
services: | ||
bot: | ||
build: . | ||
restart: always | ||
ports: | ||
- 80:4000 | ||
- 443:4000 | ||
- 4000:4000 | ||
environment: | ||
- NODE_ENV=production | ||
- PORT=4000 | ||
- URL | ||
- TELEGRAM__TOKEN | ||
- TELEGRAM__USERNAME | ||
- TELEGRAM__SECRET_PATH |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "@cryptowl/bot", | ||
"version": "0.1.0", | ||
"description": "", | ||
"private": true, | ||
"main": "src/index.js", | ||
"scripts": { | ||
"dev": "nodemon src/index.js --delay 1", | ||
"start": "node src/index.js", | ||
"lint": "eslint ." | ||
}, | ||
"files": [ | ||
"src", | ||
"docs", | ||
"config" | ||
], | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cryptowljs/cryptowl-bot.git" | ||
}, | ||
"author": { | ||
"email": "[email protected]", | ||
"name": "Patricio López Juri", | ||
"url": "https://lopezjuri.com", | ||
"telegram": "mrpatiwi" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@cryptolatam/cryptomkt": "^0.2.1", | ||
"@cryptolatam/money": "^0.1.7", | ||
"@cryptolatam/surbtc": "^0.2.1", | ||
"axios": "^0.16.2", | ||
"bluebird": "^3.5.1", | ||
"dedent": "^0.7.0", | ||
"dotenv": "^4.0.0", | ||
"koa": "^2.4.1", | ||
"koa-bodyparser": "^4.2.0", | ||
"koa-logger": "^3.1.0", | ||
"koa-router": "^7.3.0", | ||
"lodash": "^4.17.4", | ||
"moment": "^2.19.1", | ||
"nconf": "^0.8.5", | ||
"rxjs": "^5.4.2", | ||
"telegraf": "^3.17.2" | ||
}, | ||
"optionalDependencies": {}, | ||
"peerDependencies": {}, | ||
"devDependencies": { | ||
"eslint": "^4.9.0", | ||
"eslint-config-prettier": "^2.6.0", | ||
"eslint-plugin-prettier": "^2.3.1", | ||
"nodemon": "^1.12.1", | ||
"prettier": "^1.7.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
const Telegraf = require("telegraf"); | ||
|
||
module.exports = function createBot(options) { | ||
const { config } = options; | ||
|
||
const bot = new Telegraf(config.get("TELEGRAM:TOKEN"), { | ||
username: config.get("TELEGRAM:USERNAME"), | ||
}); | ||
bot.telegram.setWebhook(`${config.get("URL")}/${config.get("TELEGRAM:SECRET_PATH")}`); | ||
|
||
bot.command("help", ctx => ctx.reply("Try send a sticker!")); | ||
bot.hears("hi", ctx => ctx.reply("Hey there!")); | ||
|
||
return bot; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const path = require("path"); | ||
const nconf = require("nconf"); | ||
const dotenv = require("dotenv"); | ||
|
||
const SEPARATOR = ":"; | ||
|
||
// From /config/*.json | ||
function fromJSON(name) { | ||
return path.join(__dirname, "..", "config", `${name}.json`); | ||
} | ||
|
||
// Method to create a sub-configuration from this object | ||
nconf.Provider.prototype.sub = function sub(...args) { | ||
const generated = new nconf.Provider(); | ||
generated.defaults(this.get(args.join(SEPARATOR))); | ||
return generated; | ||
}; | ||
|
||
module.exports = function configuration(subtree = null) { | ||
dotenv.config(); | ||
|
||
const config = new nconf.Provider({ separator: SEPARATOR }); | ||
|
||
// Priorice cli arguments and then environment. | ||
config.argv().env("__"); | ||
|
||
// Sane defaults | ||
config.defaults({ | ||
NODE_ENV: "development", | ||
}); | ||
|
||
// Check and set NODE_ENV | ||
const environment = config.get("NODE_ENV"); | ||
|
||
// Load from environment file | ||
config.file("environment", { | ||
file: fromJSON(environment), | ||
}); | ||
|
||
// Default fallback | ||
config.file("default", { | ||
file: fromJSON("default"), | ||
}); | ||
|
||
// Set URL | ||
config.set("URL", config.get("APP_URL") || config.get("NOW_URL") || config.get("URL")); | ||
|
||
// Throw error if missing | ||
config.required(["URL", "TELEGRAM:TOKEN", "TELEGRAM:USERNAME", "TELEGRAM:SECRET_PATH"]); | ||
|
||
// Return a sub-tree of the config object is needed | ||
return subtree ? config.sub(subtree) : config; | ||
}; |
Oops, something went wrong.