Git Product home page Git Product logo

notes-app's Introduction

Notes

A simple Telegram mini app that lets you take notes.

Features

  • Text formatting capabilities.
  • Supports Telegram entities: usernames, hashtags, and others.
  • Ability to share the notes as Telegram messages.

Architecture

The front end is powered by React and Lexical. The back end persists data in a PostgreSQL database, and can host a Bot API webhook at the same time.

Development

Prerequisites

To work on this project, you first need to:

  • Install Git, Deno, Node.js, and optionally pnpm if you don’t already have them. Docker will also be needed if you don’t already have a PostgreSQL server running and you want to follow the guide here to setup one.

  • Have a bot with a Web App configured properly. We’ll guide you through this, so you don’t need to worry it for now. All you need is a Telegram account.

Setting up PostgreSQL

If you don’t already have access to a running PostgreSQL server, you can start one using Docker this way:

docker run -d --name notes-app_postgres -p 127.0.0.1:5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -e POSTGRES_DB=main -d postgres

This will pull a recent version of the postgres image and start an instance of it under the name notes-app_postgres and start listening for connections on localhost, port 5432. The URI for connecting to it would be postgresql://[email protected]/main.

Cloning and configuring

  1. Clone the repository.
git clone --depth 1 https://github.com/roj1512/notes-app.git
  1. cd into the clone and create a .env file.
cd notes-app/
touch .env
  1. Add the required variables to the .env file you just created in the following format.
BOT_TOKEN=1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ
POSTGRESQL_URI=postgres://[email protected]/main
POLLING=1 # Whether to use polling

The BOT_TOKEN is the bot token @BotFather gave you. The POSTGRESQL_URI is your PostgreSQL connection URI, and it is postgres://[email protected]/main if you have set up your PostgreSQL server by following the above guide.

Telegram-side configuration

Method 1: Test server

  1. Open the Telegram app, and switch to test servers.

    • Telegram Desktop: Open the menu using the button in the top left corner, right click Add Account while holding Alt+Shift, and choose Test Server.
    • Telegram macOS: Sequentially click Settings in the tab bar until the debug menu opens, and click Add Account while holding Cmd.
    • Telegram iOS: Sequentially tap Settings in the tab bar until the debug menu opens, open Accounts > Login to another account > Test.
  2. Enter your phone number to sign up or log in.

  3. Send /newbot to @BotFather, and answer the questions to create a bot.

  4. Use the /newapp command to create a Web App. Choose the bot you’ve just created, follow the instructions, and when prompted for the URL, send the following URL.

http://localhost:3000
  1. Edit your .env to include the following variable.
TEST=1
  1. Since the app has features that leverage inline mode, you will also have to enable inline mode using the /setinline command.

Method 2: Production server

  1. Use a traffic tunneling service like Pagekite, Cloudflare Tunnel or ngrok to route a public https endpoint to your localhost:3000.

  2. Send /newbot to @BotFather, and answer the questions to create a bot.

  3. Use the /newapp command to create a Web App. Choose the bot you’ve just created, follow the instructions, and when prompted for the URL, send it the URL provided by your tunnel service.

  4. Since the app has features that leverage inline mode, you will also have to enable inline mode. To do that, use /setinline.

Starting the development server

  1. To watch the front end source and rebuild it on each change, open a terminal, cd into the app/ directory, install the dependencies if you haven’t already, and run the dev script.
cd app/ # Run this from the notes-app/
pnpm install # You can use any other package manager, but pnpm is recommended
pnpm dev
  1. To start the back end, open another terminal, cd into the app/, and run the dev task.
cd api/ # Run this from notes-app/
deno task dev

Deployment with Docker

A publicly available image of this project can be found on Docker Hub.

  1. Copy docker-compose.yml to the machine where you plan to deploy the project on.
  2. Create .env file next to the docker-compose.yml, and specify the following variables.
# Only BOT_TOKEN is required.
BOT_TOKEN=1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ

# The public https URL where the app will be available at. Recommended but not necessary.
WEB_APP_URL=https://your-domain.com

# You can also specify where the server will accept connections from. Don't forget to edit docker-compose.yml if you set a different port.
HOST=127.0.0.1
PORT=3000
  1. Create a volume named notes-app.
docker volume create notes-app
  1. Start the containers.
docker compose up -d
  1. Setup a reverse proxy for localhost:3000 using a web server like NGINX or Caddy, connect it to your domain, and setup TLS.

  2. Change the Web App URL in @BotFather to where your deployment is accessible from.

License

This project is licensed under the BSD-3-Clause license.

notes-app's People

Contributors

roj1512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.