[[https://actions-badge.atrox.dev/benkio/sBots/goto][file:https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fbenkio%2FsBots%2Fbadge&style=flat]] [[https://scala-steward.org][file:https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=]] [[Cats Friendly Badge][https://typelevel.org/cats/img/cats-badge-tiny.png]]
A repository containing the following bots developed in Scala.
Author: https://t.me/Benkio
** Bots
| Telegram Bot | Character Link |
| https://t.me/RichardPHJBensonBot | [[https://en.wikipedia.org/wiki/Richard_Benson_(musician)][Richard Philip Henry John Benson]] |
| https://t.me/YouTuboAncheI0Bot | [[https://www.youtube.com/channel/UCO66DuFYNFMdR8Y31Ire1fg][Youtubo Anche Io]] |
| https://t.me/ABarberoBot | [[https://en.wikipedia.org/wiki/Alessandro_Barbero][Alessandro Barbero]] |
| https://t.me/M0sconiBot | [[https://en.wikipedia.org/wiki/Germano_Mosconi][Germano Mosconi]] |
| https://t.me/XahLeeBot | [[http://xahlee.info/][Xah Lee]] |
| https://t.me/CalandroBot | |
** Required Software
** Add Data to the Bots
Each bot contains a ~resources~ folder. You need to put in there
the ~.token~ file containing the telegram key specific to each
bot.
Each bot also uses a ~SQLite~ Database! So you need
to provide the path to the database into the ~application.conf~
or just set up the specific environment variables. No need to put
the files in resources since those will be fetched from the web
via URLs.
Check [[https://youtu.be/T-AfAvJLSJE][this video]] for a complete rundown on how to add files to a bot.
** Database Setup
There's a module called ~botDB~, if opportunely configured,
when launched, it applies the migrations and populates a bot
database. Just set up the ~application.conf~ correctly with the DB
path, see the DB in the root of the project, and the location of
the ~json~. There should be a ~json~ file at the root of each bot
module
** Compile and Test
Several command alias are defined in the project to group together useful ~sbt~ commands:
~validate~ :: compile clean and test. It includes the ~fix~ command and it is run in the CI.
Moreover, there are tests excluded from the CI because they are quite slow. In this category, there is one that checks all the media links in the DB and can be called manually by ~sbt integration/runIntegrationScalaTests~
** Run the Bots *** Long Polling Under Windows use the git bash terminal.
./lunch.sh # I know it's lunch not launch :)
* Webhook ** Localhost
- Export the webhook host, locally using [[https://ngrok.com/][ngrok]], [[https://github.com/beyondcode/expose][expose]] or [[https://github.com/agrinman/tunnelto][tunnelTo]]. example: ~./expose share http://localhost:8080~
- Change the entry ~WEBHOOK_HOST_URL~ with the name of the host from the previous step or change it in ~~sBots/main/src/main/resources/application.conf~
- run ~sbt assembly~
- run ~java -cp main/target/scala-3.3.1/main.jar com.benkio.main.MainWebhook~
**** Docker
TODO: There's already a ~main/Dockerfile~ with the command to run the webhook, but still it needs to be tested and visible from outside
Also check [[https://expose.dev/docs/getting-started/installation#as-a-docker-container][expose on docker]]. In order to may make it discoverable from telegram API.
** Continuous Deployment
There should be a pipeline on master, running after the other workflows, that should deploy build, deploy and run the bots remotely on Oracle already. Every new master commit will result in a deployment.
** Deploy on Oracle Cloud Infrastructure VM *** Setup
**** Webhook Extra Configuration
If something doesn't work, please follow [[https://core.telegram.org/bots/webhooks#the-verbose-version][this guide]] and update the documentation accondingly Follow these steps to set up the server property:
Server Prerequisites :: Check [[https://core.telegram.org/bots/webhooks#the-short-version][this page]] for the prerequisites required by telegram to work with webhook. In our case, we choose port 8443 for SSL connection.
Open Port on OCI Subnet :: The instance where the bots are running needs to have an attached VNICs([[https://docs.oracle.com/iaas/Content/Network/Tasks/managingVNICs.htm][Virtual Network Interface Card]]) with a subnet. The subnet will have a default security list containing the rules for the ports available from outside. Add a new rule for the port required and save it. The parameters to use are:
Test the port is open :: by spawning a server with the command ~python3 -m http.server 8443~ and try to open a browser tab to the server. eg http://129.152.27.196:8443/
Generate a keystore JKS :: On the server, using the commands on [[https://core.telegram.org/bots/self-signed][this page]], follow the instruction for the java keystore, pasting each command one by one. For the correct keystore password to use, check the application.conf
. Example
$ keytool -genkey -alias sbots -keyalg RSA -keystore sbotsKeystore.jks -keysize 2048 -validity 360 Enter keystore password: Re-enter new password: Enter the distinguished name. Provide a single dot (.) to leave a sub-component empty or press ENTER to use the default value in braces. What is your first and last name? What is the name of your organizational unit? Unknown: What is the name of your organization? Unknown: What is the name of your City or Locality? Unknown: What is the name of your State or Province? Unknown: What is the two-letter country code for this unit? Unknown: Is CN=129.152.27.196, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
Generating 2,048 bit RSA key pair and self-signed certificate (SHA384withRSA) with a validity of 360 days for: CN=129.152.27.196, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
Convert the keystore to PEM :: following the commands in the link above. eg:
$ keytool -importkeystore -srckeystore sbotsKeystore.jks -destkeystore sbots.p12 -srcstoretype jks -deststoretype pkcs12 Importing keystore sbotsKeystore.jks to sbots.p12... Enter destination keystore password: Re-enter new password: Enter source keystore password: Entry for alias sbots successfully imported. Import command completed: 1 entries successfully imported, 0 entries failed or cancelled $ openssl pkcs12 -in sbots.p12 -out sbotsCertificatePub.pem -nokeys
*** Deploy