# 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! ## 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 Copy `freepbx-stats.service` to `/etc/systemd/system`, then run `systemctl enable --now freepbx-stats` to make it run in the background!