readme.md
[](https://travis-ci.org/12-cactus/espinoso)[](https://codeclimate.com/github/12-cactus/espinoso)[](https://codeclimate.com/github/12-cactus/espinoso/coverage)[](https://codeclimate.com/github/12-cactus/espinoso) # Espinoso :: Telegram Bot ## Installation ### 1. Clone project ```bash$ cd ~/your-dev-path$ git clone https://github.com/12-cactus/espinoso.git``` ### 2. Create your own Espinoso Dev Bot > If you like to learn more about bots, go to [https://core.telegram.org/bots](https://core.telegram.org/bots) Open your telegram app and search **BotFather** (Telegram bot using for manager bots). Type `/newbot` and follow instructions. You can use the name you prefer, butit would be nice to use **EspinosoDevYOURINITIALSBot**.For example, if your name is _John Doe_, your bot could be called **EspinosoDevJDBot**.When finish, **BotFather** will give you a token for your bot, save it for later.**BotFather** should also given you a link like this _t.me/EspinosoDevYOURINITIALSBot_, click on itto open a chat with your bot. ### 3. Install environment First install [VirtualBox](https://www.virtualbox.org/wiki/Downloads)and [Vagrant](https://www.vagrantup.com/downloads.html).Then install Homestead (below is a quickly installation, if you wanta better understanding, go to [Laravel documentation](https://laravel.com/docs/5.4/homestead#installation-and-setup)) ```bash$ vagrant box add laravel/homestead``` When finish (it will take some time) ```bash$ cd ~$ git clone https://github.com/laravel/homestead.git Homestead$ cd Homestead$ git checkout v5.4.0$ bash init.sh``` After install, you need to configure Homestead. Open `Homestead.yaml`and edit `folders`, `sites` & `databases` with something like this: ```yamlfolders: - map: ~/your-dev-path/espinoso to: /home/vagrant/espinososites: - map: espinoso.local to: /home/vagrant/espinoso/public php: "7.3" databases: - espinoso``` Save & Exit. Then you need to add site to your hosts file.Open `/etc/hosts` and add this line to the end of file ```192.168.10.10 espinoso.local``` ### 4. Start Homestead & Init your Bot Generate RSA SSH Keys ```$ ssh-keygen # or read https://www.cyberciti.biz/faq/linux-generating-rsa-keys/``` Enter Homestead ```bash$ cd ~/Homestead$ vagrant up$ vagrant ssh``` Inside Homestead ```bashhomestead:$ ngrok http espinoso.local:80``` It will open a black _ngrok_ window. It tell you the url to use and you can view every http request. To associate your bot with your _ngrok_ site, you need to open a new terminal ```bash$ cd ~/Homestead$ vagrant sshhomestead:$ cd espinosohomestead:$ cp .env.example .envhomestead:$ composer installhomestead:$ artisan key:generate``` Open `.env` and search `TELEGRAM_BOT_TOKEN` key. Copy your **saved token** and paste into var, like this: `TELEGRAM_BOT_TOKEN=123456:ABCDEF` Add this key too `OPENWEATHER_API_KEY:be37573a09446418bdaaab4699e4895b` Finally, you need to associate _ngrok_ service as webhook. So, just run ```bash# This command set ngrok publish services as webhookhomestead:$ artisan espi:nghook``` Now your bot is ready. ### That's all Now you can be able to interact with your espinoso bot. Open it in a chat and write _macri_. It should response _Gato_. **IMPORTANT!** _ngrok_ change url every time you restart server. For daily usage or when you restart Homestead or _ngrok_, you need to re-associate them. Terminal 1: ```$ cd ~/Homestead && vagrant up && vagrant sshhomestead:$ ngrok http espinoso.local:80``` Terminal 2: ```bash$ cd ~/Homestead && vagrant sshhomestead:$ cd espinosohomestead:$ artisan espi:nghook``` ### Testing ```bashhomestead:$ cd espinosohomestead:$ composer installhomestead:$ phpunit test```