Skip to content

abigpotostew/microcosmbot

Repository files navigation

MicroCosmBot

MicroCosmBot is a telegram bot for creating token gated telegram group chats for cosmos assets.

Apps and Packages

  • web: the NextJS web application that also runs the telegram bot
  • bot: all the bot logic
  • eslint-config-custom: eslint configurations (includes eslint-config-next and eslint-config-prettier)
  • tsconfig: tsconfig.jsons used throughout the monorepo
  • tailwind-config: tailwind.config.jss used through web and docs application as well as package/ui components

Each package/app is 100% TypeScript.

Development Setup

  • Setup a mysql8 database. Copy the connection string to your env in DATABASE_URL. Run npx prisma db push from the packages/db directory to deploy the schema.
  • Acquire a telegram bot token from @BotFather
  • Enable bot group settings via botfather.
  • Create a webhook to your localhost web port. I can recommend https://tunnelmole.com/ -- tmole 3000. Set this tunnel url to your BASEURL env variable.
  • Copy apps/web/.env.sample to apps/web/.env and fill in the values.
  • Run your bot locally with turbo dev in the apps/web directory.
  • Call the config api to tell the bot where to send updates. curl -X GET http://localhost:3000/api/bot/<your bot key>/config
  • You will now receive bot updates from telegram to your local machine.
  • For testing the background checks, create an upstash QStash. Save QSTASH_URL, QSTASH_TOKEN, QSTASH_CURRENT_SIGNING_KEY, and QSTASH_NEXT_SIGNING_KEY from qstash

Deployment

  • Get your bot info and store the JSON in NEXT_PUBLIC_GETME_BOT_INFO (one time)
    • Call the telegram api https://api.telegram.org/bot<your-bot-api-key>/getMe and copy the result field object in the environment variable.
    • This helps speed up the api calls because grammy will not have to call this each time a function boots.
  • Setup https://console.upstash.com/qstash which is used for the cron job to periodically check nft token ownership. Copy the key to your env.
  • Deploy to vercel through the git integration.

Cron

A vercel cron job enqueues a job that checks the nft token ownership of all users in the database. If a user no longer owns the token, they are removed from the database and banned from the group. This is to ensure that only users who own the token can be in the group.

Configure how often this runs in vercel.json. The default is every 2 hours.

Utilities

This turborepo has some additional tools already setup for you:

Build

To build all apps and packages, run the following command:

cd nouns-stream
yarn build

Develop

To develop all apps and packages, run the following command:

cd nouns-stream
yarn dev

Testing

The web and docs NextJS projects are setup to run with Vitetest and web3 is setup to run test via Forge.

To test all apps and packages, run the following command:

cd nouns-stream
yarn test

To run tests in watch mode, run the following command:

cd nouns-stream
yarn test:watch

Remote Caching

Turborepo can use a technique known as Remote Caching to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can create one, then enter the following commands:

cd microcosms
npx turbo login

This will authenticate the Turborepo CLI with your Vercel account.

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your turborepo:

npx turbo link

Useful Links

Learn more about the power of Turborepo:

License

This project is licensed under the GPL licence. See LICENSE.md for details.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Contributor wish list:

6dp: factory/neutron1ffus553eet978k024lmssw0czsxwr97mggyv85lpcsdkft8v9ufsz3sa07/astro factory/neutron1zlf3hutsa4qnmue53lz2tfxrutp8y2e3rj4nkghg3rupgl4mqy8s5jgxsn/xASTRO

ideas:

  • change the auth type to sign arbitrary if it's non mobile
  • allow admin to configure how the greetings work