Giter VIP home page Giter VIP logo

tipalph's Introduction

TipAlph

This repository hosts the code of @TipAlphBot, a bot that allows you to send and receive Alephium with Telegram!
This project was developed as part of the Alephium Hackathon.

This project uses Node lts/hydrogen (v18.19.0) and NPM (v10.2.3).

Dependencies

To be added soon.

How to deploy

The only supported way to deploy the code actually is using Docker, as the code uses Docker secrets.
To deploy the bot:

  1. create a bot by chatting with Bot Father and get your bot token
  2. get Alephium related elements:
    1. get a fresh mnemonic for the wallet hosting everybody's address. Make sure to not create and new address on this wallet.
    2. get an address for collecting the operator's fees (if you want some)
  3. clone this repository git clone https://github.com/notrustverify/tipALPH
  4. copy the .env.example into .env file: cp .env.example .env
  5. change the variable in the .env file according to your setup (fullnode address, โ€ฆ) and insert the bot token and the address for fees in the .env file
  6. copy your freshly created mnemonic in a file named bot_mnemonic.txt in the secrets folder
  7. create a new TipAlph docker image with npm run package
  8. run docker compose --profile tipalph up -d to run the fresh docker image.

On the logs (with docker compose --profile tipalph logs -f), you should see a successful connection to the database as well as a ready and synced NodeProvider.
The telegram bot should now be available.

How to develop

To work on the bot, we suggest to use the devnet. It allows for faster testing and better testing conditions (easier generation of tokens).
Follow the same procedure as for deployment, but specify a fullnode on the testnet and "NETWORK=testnet" in the .env file. The provided fees collection address and mnemonic for the wallets should also be on the testnet. We would advise you to use a different database as well, if you previously deployed on a database.

There is multiple way of running the code application:

  • using npm run start: will transpile the Typescript into Javacript and use node to execute it
  • using npm run dev: will directly execute the Typescript code using tsx
  • using npm run watch: as npm run dev but in watch mode (will reload the program if a file changed or ENTER is pressed)
  • as a docker container (see below)

These are defined in the package.json file.

How to test

Before running the test suite, you need to have a fullnode on the devnet accessible to http://127.0.0.1:22973.
The easiest way to do it is to start a docker container before running the test suite. This can be simply archived by running: docker compose --profile test up -d and waiting some seconds.

Tests can be run using npm run test.

To add coverage, edit the jest.config.cjs file and set collectCoverage to true;

Alephium side

We wrote some code to test the alephium client that our bot uses, to ensure that we correctly use it.

Telegram side

It seems to be really complicated to test Telegram bots (integration tests, by sending Telegram messages). If you know how to do it, please reach out to us or do a PR!

Building the docker container

We provide a Dockerfile to build the container. The easiest way to build a new image is by running the npm run package commands, which takes care of settings the appropriate tags for you.

To create a docker container from the freshly built image, we recommend using the provided docker-compose.yml file with the required configuration. Once you provided the required dependencies, simply do a docker compose --profile tipalph up to spin a new container.

License

The code in this repository (without the dependencies it relies on), is released under the GNU GENERAL PUBLIC LICENSE v3 or later license.

tipalph's People

Contributors

amadeous avatar oheka avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

nit27

tipalph's Issues

Better structure for commands

All the commands are currently defined in a single file (bot.ts), which is not modular and makes it hard to keep up. The definition of the commands should be splitted in multiple files in the commands folder. Commands should exhibit a similar interface.
Common mother class should specify

  • name, description, usage
  • if command is private only or not
  • have a method to check the validity of the request
  • have a method to process the request

Ideally, a mother class should define additional pre-operations and post-operations to be performed before and after the processing of the command (to allow to filter users or validate parameters).

Tip by tagging

Allow /tip 100 @some-user. Remove the need to reply to a message.
Since Telegraf API does not seem to provide the reference of the tagged user, will only fetch it by username, not id.

Dockerfile

Have a 2-stages docker build process to transpile & run the code.

Withdraw all

Would it be interesting to be able to withdraw everything in one /withdraw command ?

Something like /withdraw <address> and then the user will have all of his tokens + ALPH withdrawed

Fix process.processTicksAndRejections error

From time to time, an unknown error occurs. It is probably linked to the sending of the transaction update as the transaction is completed, but the display says it fails.

GeneralError: failed to tip
    at file:///usr/app/telegram/bot.js:150:35
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    context: { sender_id: x, received_id: y, amount: '1' }
}

Consolidate UTXO

When required, the Unspent TransaXion Outputs (UTXO) should be be consolidated.
This can be performed by sending all the token of a user to itself.

Some users are invisible to the bot

So far, it seems that it may be due to

  • Privacy settings of the user -> give hint in error message
  • If user has no username, the bot cannot register them since it is a mandatory field

Warn user if tipped without '$'

The token field will be empty but the first word of the "reason" (in the regex) would be a token.
If it is the case, prevent transaction and warn user or ideally, use buttons to ask user confirmation (select ALPH or written token)

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.