12-cactus / espinoso

:cactus: Unfriendly Bot for Telegram
3 stars 3 forks source link

Build Status Code Climate Test Coverage Issue Count

Espinoso :: Telegram Bot

Installation

1. Clone project

$ 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

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, but it 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 it to open a chat with your bot.

3. Install environment

First install VirtualBox and Vagrant. Then install Homestead (below is a quickly installation, if you want a better understanding, go to Laravel documentation)

$ vagrant box add laravel/homestead

When finish (it will take some time)

$ 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:

folders:
    - map: ~/your-dev-path/espinoso
      to: /home/vagrant/espinoso
sites:
    - 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

$ cd ~/Homestead
$ vagrant up
$ vagrant ssh

Inside Homestead

homestead:$ 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

$ cd ~/Homestead
$ vagrant ssh
homestead:$ cd espinoso
homestead:$ cp .env.example .env
homestead:$ composer install
homestead:$ 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

# This command set ngrok publish services as webhook
homestead:$ 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 ssh
homestead:$ ngrok http espinoso.local:80

Terminal 2:

$ cd ~/Homestead && vagrant ssh
homestead:$ cd espinoso
homestead:$ artisan espi:nghook

Testing

homestead:$ cd espinoso
homestead:$ composer install
homestead:$ phpunit test