|
1 |
| -# ansible-role-php-telegram-bot |
2 |
| -Ansible role to set up PHP Telegram Bots. |
| 1 | +# Ansible Role for PHP Telegram Bot |
| 2 | + |
| 3 | +<!-- [![Build Status][1]][2] --> |
| 4 | + |
| 5 | +**This project is still a work in progress, use at your own risk! For now, you will most probably have to explore the code to understand what this role does exactly.** |
| 6 | + |
| 7 | +Installs and configures [PHP Telegram Bots][php-telegram-bot] on Debian/Ubuntu servers. |
| 8 | +This role uses the [PHP Telegram Bot Manager][php-telegram-bot-manager] project and makes use of [`vlucas/phpdotenv`][phpdotenv] for all configurable values. |
| 9 | + |
| 10 | +**Note:** This role does not install any web or database server! |
| 11 | +It assumes that you have a functioning web server with PHP and composer installed. |
| 12 | + |
| 13 | +There are two different ways this role will work for you: |
| 14 | +**A basic default bot** |
| 15 | +This method installs a very basic bot into your defined working directory. |
| 16 | +All parameters are passed directly using the `php_telegram_bot_bots` array. |
| 17 | + |
| 18 | +**An existing project that exists in a git repository** |
| 19 | +When you already have an existng project that makes use of the [PHP Telegram Bot Manager][php-telegram-bot-manager], you can simply define the path to your git repository using the `project_repo` (and `project_repo_branch`) parameters in the `php_telegram_bot_bots` array. |
| 20 | + |
| 21 | +## Requirements |
| 22 | + |
| 23 | +- git (can be installed using the [`geerlingguy.git`][geerlingguy.git] role) |
| 24 | +- Composer (can be installed using the [`geerlingguy.composer`][geerlingguy.composer] role) |
| 25 | + |
| 26 | +**Webserver** |
| 27 | +You can use whatever you want. You just need to create a site/vhost that points to the correct root of the Telegram Bot directories. |
| 28 | +I recommend using Nginx, which can be installed easily with the [`geerlingguy.nginx`][geerlingguy.nginx] role. |
| 29 | + |
| 30 | +**Database** |
| 31 | +To use the database for your bot(s), make sure you have a functioning connection to the database server. |
| 32 | +If it's on the same machine, you can use the the [`geerlingguy.mysql`][geerlingguy.mysql] role. |
| 33 | +For any external server, you just need to be able to access the database with your credentials. |
| 34 | + |
| 35 | +## Role Variables |
| 36 | + |
| 37 | +``` |
| 38 | +php_telegram_bot_composer_package: noplanman/telegram-bot-manager |
| 39 | +php_telegram_bot_composer_version: '' |
| 40 | +php_telegram_bot_mysql_structure: vendor/longman/telegram-bot/structure.sql |
| 41 | +
|
| 42 | +php_telegram_bot_websrv_user: www-data |
| 43 | +php_telegram_bot_websrv_group: www-data |
| 44 | +
|
| 45 | +php_telegram_bot_bots: [] |
| 46 | +
|
| 47 | +# php_telegram_bot_bots: |
| 48 | +# # Simple bot (minimal) |
| 49 | +# - api_key: 12345:api_key |
| 50 | +# working_dir: /var/www/simplebot_minimal |
| 51 | +# |
| 52 | +# # Simple bot (with db) |
| 53 | +# - api_key: 12345:api_key |
| 54 | +# bot_username: my_bot |
| 55 | +# working_dir: /var/www/simplebot_with_db |
| 56 | +# mysql: |
| 57 | +# host: localhost |
| 58 | +# user: root |
| 59 | +# password: root |
| 60 | +# database: db |
| 61 | +# |
| 62 | +# # Simple bot (with webhook) |
| 63 | +# - api_key: 12345:api_key |
| 64 | +# bot_username: my_bot |
| 65 | +# working_dir: /var/www/simplebot_with_webhook |
| 66 | +# secret: super-secret |
| 67 | +# webhook: |
| 68 | +# url: my.webhook.url |
| 69 | +# |
| 70 | +# # Project bot (with webhook) |
| 71 | +# - api_key: 12345:api_key |
| 72 | +# bot_username: my_bot |
| 73 | +# project_repo: https://projectrepo.git |
| 74 | +# project_dotenv: prod.env.j2 |
| 75 | +# working_dir: /var/www/projectbot |
| 76 | +# secret: super-secret |
| 77 | +# webhook: |
| 78 | +# url: project.webhook.url |
| 79 | +# mysql: |
| 80 | +# host: db.server |
| 81 | +# user: root |
| 82 | +# password: root |
| 83 | +# database: db |
| 84 | +# structure: my-custom-db-structure.sql |
| 85 | +``` |
| 86 | + |
| 87 | +Available fields for `php_telegram_bot_bots` entry are the ones available for the [PHP Telegram Bot Manager][php-telegram-bot-manager]. Simply use YAML format to define variables in the same structure as the [`manager.php`][manager.php-example] parameters array. |
| 88 | + |
| 89 | +## Role Tags |
| 90 | + |
| 91 | +Each part of the setup has a tag. |
| 92 | + |
| 93 | +``` |
| 94 | +php_telegram_bot:install # Installation of all bots. |
| 95 | +php_telegram_bot:database # Set up the databases. |
| 96 | +php_telegram_bot:webhook # Set the webhooks. |
| 97 | +``` |
| 98 | + |
| 99 | +## Dependencies |
| 100 | + |
| 101 | +None. |
| 102 | + |
| 103 | +## Example Playbook |
| 104 | + |
| 105 | +``` |
| 106 | +--- |
| 107 | +- hosts: www-server |
| 108 | + become: yes |
| 109 | + roles: |
| 110 | + - php-telegram-bot.php-telegram-bot |
| 111 | +``` |
| 112 | + |
| 113 | +## License |
| 114 | + |
| 115 | +MIT |
| 116 | + |
| 117 | +[1]: https://travis-ci.org/php-telegram-bot/ansible-role-php-telegram-bot.svg?branch=master "Travis-CI Build Status" |
| 118 | +[2]: https://travis-ci.org/php-telegram-bot/ansible-role-php-telegram-bot "Travis-CI Tests" |
| 119 | +[php-telegram-bot]: https://github.com/php-telegram-bot/ "PHP Telegram Bot" |
| 120 | +[php-telegram-bot-manager]: https://github.com/php-telegram-bot/telegram-bot-manager "PHP Telegram Bot Manager" |
| 121 | +[manager.php-example]: https://github.com/php-telegram-bot/example-bot/blob/master/manager.php "manager.php example" |
| 122 | +[phpdotenv]: https://github.com/vlucas/phpdotenv/ "phpdotenv" |
| 123 | +[geerlingguy.git]: https://github.com/geerlingguy/ansible-role-git "Git Ansible role" |
| 124 | +[geerlingguy.composer]: https://github.com/geerlingguy/ansible-role-composer "Composer Ansible role" |
| 125 | +[geerlingguy.nginx]: https://github.com/geerlingguy/ansible-role-nginx "Nginx Ansible role" |
| 126 | +[geerlingguy.mysql]: https://github.com/geerlingguy/ansible-role-mysql "MySQL Ansible role" |
0 commit comments