Git Product home page Git Product logo

xguard-bot's Introduction

XGuardChatBot

This is a console application to transfer certain messages from Facebook to certain Telegram channels.

The App's latest version is 1.0.0

Telegram Bot API version is 6.4 (December 30, 2022)

Facebook API is v17.0

Requirements

  • Docker Engine
  • DockerCompose script aka docker-compose
  • *nix system

Preparing to start

  • create a .env.local file in the root
  • put everything from the root .env file with blank after =
  • create a .env.local file in ./App/
  • put and change everything you need there
  • wisely choose every value

Start services

  • The external network creates as
docker network create xguard-service-bot-network
  • The main services start as
DATABASE_USER=<DATABASE_USER> DATABASE_PASSWORD=<DATABASE_PASSWORD> DATABASE_NAME=<DATABASE_NAME> DATABASE_HOST=<DATABASE_HOST> docker-compose -f Service/Docker/docker-compose.yml up -d
  • The mockoon service (an independent service) starts as
docker-compose -f Service/mockoon/docker-compose.yml up -d
  • Execute migrations (see the section Migrations)

Basic usage

  • Get to the app container as
docker exec -ti xguard-service-bot-php sh
  • Get to the database container as
docker exec -ti xguard-service-bot-database sh
  • Get to the mockoon container as
docker exec -ti xguard-service-bot-mockoon sh

Basic commands

  • The default command is
bin/bot
bin/bot shared:index:list
  • The default CRUD commands to set relations between FacebookChannel and TelegramBot are
bin/bot shared:channel_to_bot:create --channelId=<channelId> --botId=<botId>
bin/bot shared:channel_to_bot:read
bin/bot shared:channel_to_bot:update --id=<id> --channelId=<channelId> --newChannelId=<newChannelId> --botId=<botId> --newBotId=<newBotId>
bin/bot shared:channel_to_bot:delete --id=<id> --channelId=<channelId> --botId=<botId>
  • The Telegram CRUD commands to set TelegramBot are
bin/bot telegram:bot:create --botName=<botName> --token=<token>
bin/bot telegram:bot:read
bin/bot telegram:bot:update --id=<id> --botName=<botName> --newBotName=<newBotName> --token=<token> --newToken=<newToken>
bin/bot telegram:bot:delete --id=<id> --botName=<botName> --token=<token>
  • The Telegram CRUD commands to set TelegramChannel are
bin/bot telegram:channel:create --channelName=<channelName> --chatId=<chatId>
bin/bot telegram:channel:read
bin/bot telegram:channel:update --id=<id> --channelName=<channelName> --newChannelName=<newChannelName> --chatId=<chatId> --newChatId=<newChatId>
bin/bot telegram:channel:delete --id=<id> --channelName=<channelName> --chatId=<chatId>
  • The Telegram CRUD commands to set relations between TelegramBot and TelegramChannel are
bin/bot telegram:channel_to_bot:create --channelId=<channelId> --botId=<botId>
bin/bot telegram:channel_to_bot:read
bin/bot telegram:channel_to_bot:update --id=<id> --channelId=<channelId> --newChannelId=<newChannelId> --botId=<botId> --newBotId=<newBotId>
bin/bot telegram:channel_to_bot:delete --id=<id> --channelId=<channelId> --botId=<botId>
  • The Telegram command posts messages through the TelegramBot is
bin/bot telegram:message:post --baseURI="https://api.telegram.org/bot<token>/<method>" --botName=<botName> --channelName=<channelName>
  • The Facebook CRUD commands to set FacebookBot are
bin/bot facebook:bot:create --clientId=<clientId> --clientSecret=<clientSecret> --botName=<botName> 
bin/bot facebook:bot:read
bin/bot facebook:bot:update --id=<id> --clientId=<clientId> --newClientId=<newClientId> --clientSecret=<clientSecret> --newClientSecret=<newClientSecret> --botName=<botName> --newBotName=<newBotName>
bin/bot facebook:bot:delete --id=<id> --clientId=<clientId> --clientSecret=<clientSecret> --botName=<botName>
  • The Facebook CRUD commands to set FacebookChannel are
bin/bot facebook:channel:create --channelId=<channelId> --channelName=<channelName> --channelType=<channelType>
bin/bot facebook:channel:read
bin/bot facebook:channel:update --id=<id> --channelId=<channelId> --newChannelId=<newChannelId> --channelName=<channelName> --newChannelName=<newChannelName> --channelType=<channelType> --newChannelType=<newChannelType>
bin/bot facebook:channel:delete --id=<id> --channelId=<channelId> --channelName=<channelName> --channelType=<channelType>
  • The Facebook CRUD commands to set relations between FacebookBot and FacebookChannel are
bin/bot facebook:channel_to_bot:create --channelId=<channelId> --botId=<botId>
bin/bot facebook:channel_to_bot:read
bin/bot facebook:channel_to_bot:update --id=<id> --channelId=<channelId> --newChannelId=<newChannelId> --botId=<botId> --newBotId=<newBotId>
bin/bot facebook:channel_to_bot:delete --id=<id> --channelId=<channelId> --botId=<botId>
  • The Telegram command posts messages through the TelegramBot is
bin/bot facebook:post:get --baseURI="https://graph.facebook.com/v17.0/<what>" --botName=<botName> --channelName=<channelName>

How to get requisites

Telegram

Facebook

How to fill

  • add a Telegram Bot requisites
  • add a Telegram Channel requisites
  • add a relation between Telegram Bot and Telegram Channel
  • add a Facebook Bot requisites
  • add a Facebook Channel requisites
  • add a relation between Facebook Bot and Facebook Channel
  • add a relation between Facebook Channel and Telegram bot

How to start bots

  • start getting messages from Facebook
  • start posting messages to Telegram

PHPUnit testing

  • Start a mockoon service
  • Go to the app container as
docker exec -ti xguard-service-bot-php sh
  • Start the tests as
XDEBUG_MODE=coverage vendor/phpunit/phpunit/phpunit --warm-coverage-cache --path-coverage --coverage-text --coverage-filter src/ tests/

Migrations

  • Go to the app container as
docker exec -ti xguard-service-bot-php sh
  • Execute these scripts as
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Facebook\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230403002134 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Facebook\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230711230141 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Facebook\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230712011452 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Shared\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230403002434 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Shared\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230711230141 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Shared\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230715001426 
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Telegram\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230403002134
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Telegram\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230711230141
vendor/bin/doctrine-migrations migrations:execute -n --configuration config/doctrine/migrations.yml --db-configuration config/doctrine/migrations-db.php  --up -- XGuard\\Bot\\Telegram\\Infrastructure\\Doctrine\\DBAL\\Migrations\\Version20230712011452

ToDo

  • using aimeos/map for MapCollection
  • covering at least 90% of tests
  • finalize Test\XGuard\Bot\InMemoryEntityManager
  • pagination in Facebook /posts
  • using relation between FacebookBot and FacebookChannel

xguard-bot's People

Watchers

Sergei Gardner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.