diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d4e10e0 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DISCORD_WEBHOOK_URL = +DATABASE_USER = statsBot +DATABASE_PASSWORD = statsBot +DATABASE_HOST = 127.0.0.1 +DATABASE_NAME = asteriskcdrdb \ No newline at end of file diff --git a/README.md b/README.md index f0bdb6e..c0daa4b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,27 @@ # FreePBX Stats Bot Simple bit of code to run via crontab that tracks call stats and sends them to Discord -Original code by ChatGPT and CaptainChris, thanks for the idea and base to work off! \ No newline at end of file +Original code by ChatGPT and CaptainChris, thanks for the idea and base to work off! + +## MySQL Setup +In this example we're going to assume you want to run the code on the PBX itself. + +In order for our script to access the call logs, we need to make a user on the SQL server. +- While logged in as `root` on your PBX, run `mysql -u root` to get to an SQL shell. +- Create the user with `CREATE USER 'statsBot'@'127.0.0.1' IDENTIFIED BY 'statsBot';`. The `@'127.0.0.1'` will make it only allow logins from the local machine. + - If you need the code to run on a remote machine (not your PBX), change that to the IP of the remote machine. +- Next, we need to grant `SELECT` perms for our user with `GRANT SELECT ON asteriskcdrdb.cdr TO 'statsBot'@'127.0.0.1';` + +At this point you can type `EXIT;` to exit the SQL prompt. + +## Configuring with `.env` +Configuring the script is really simple, just copy `.env.example` to `.env`, open it up, and set the values you need to change. +For anybody that's running this on their PBX directly, and used the above SQL setup, you just need to set a webhook URL! + +Otherwise, you probably know how to configure it the way you need. + +## Automatic running +For LiteNet, we're using `crontab` to run this every day at midnight. +That looks a little something like this: +`0 0 * * * cd /root/freepbx-stats/ && /usr/bin/node .` +You can edit the crontab with `crontab -e` \ No newline at end of file