A bot that uses sgID to limit access to your group to Singapore Government public officers, deployable to Vercel
- A GitHub account
- A computer with NodeJS and tools for web development
- Some familiarity with JavaScript or TypeScript
- Sign into the sgID Developer Portal.
- If this is your first time doing so, set your email to your gov.sg email address in your profile page.
- Create a new sgID client, with
NAME
andPUBLIC OFFICER DETAILS
included in the scope.
Store the secrets in a safe location. - Add
http://localhost:3000/auth/sgid/callback
to the list of Redirect URLs.
- Create a new bot by obtaining a bot token from BotFather.
- Store the bot's security token in a safe location.
- Create a database with Neon.
- Store the database's connection url in a safe location.
Generally, we recommend the use of a password manager like 1Password to store secrets. Many password managers would also feature the ability to share secrets within a team, which would be useful if you are collaborating with others to build the bot.
- Click the button above to clone and deploy this project.
- Enter the sgID secrets and Telegram bot token obtained from the previous two sections.
- Visit the sgID Developer Portal and add a Redirect URL bearing
your deployed application's domain name.
It should be in the following format:https://<project_name>-git-main-<your_github_handle>.vercel.app/auth/sgid/callback
Once the bot has been deployed, it should be added to the desired group as an admin so that it can start to moderate it.
- Start up telegov
- In the telegram group you wish to make use of the bouncer, click on the three dots > Manage group > Administrators > Add Administrator and look for your telegram bot
- The bot will create a new invite link for your group, and block entry of any new users which have not finished authentication. The invite links to any groups which you have added the bot to can be accessed via
/getInvite
for authenticated users. - Direct your new users to the bouncer bot to obtain access to your group.
Once you have created your new Telegov project from this template, follow these instructions to prepare a development environment on your computer.
$ git clone [email protected]:<your github repository>
$ cd <local dir that git cloned your repository to>
- Copy .env.example to .env
$ cp .env.example .env
- Set up an ngrok tunnel for your local machine,
setting
BOT_DOMAIN
in your .env file as you do so - Populate the rest of the .env file per Environment variables
npm run migrate
The server needs a few environment variables to be set for it to function. They are:
Name | What It Is | Example |
---|---|---|
SGID_CLIENT_ID |
The client ID given during client registration | TELEGOVSG-780ba228 |
SGID_CLIENT_SECRET |
The client secret given during client registration | asdfn_v1_6DBRljleevjsd9DHPThsKDVDSenssCwW9zfA8W2ddf/T |
SGID_PRIVATE_KEY |
The client private key given during client registration | -----BEGIN PRIVATE KEY-----... |
BOT_TOKEN |
The secret token to identify your bot to Telegram | 192830192:DSNVIELKSDFLKJSDF-3cslq |
BOT_DOMAIN |
The domain Telegram uses to send messages to your bot(*) | https://........ngrok-free.app |
DATABASE_URL |
The connection string uses to connect to your neon database | postgresql://<user>:<password>@<host>/<database>?sslmode=require |
POSTGRES_URL |
An alias for DATABASE_URL |
postgresql://<user>:<password>@<host>/<database>?sslmode=require |
(*): If not given, Telegov uses the VERCEL_BRANCH_URL
environment variable instead. In your local environment, you can use ngrok.
- Install ngrok
- Go to ngrok dashboard and create a new permanent domain
- Copy the domain and paste it in the .env file as
BOT_DOMAIN
- Run ngrok with the following command whenever you're doing local testing
$ ngrok http <YOUR_DOMAIN> 3000
- Install dependencies for Telegov
$ npm ci
- Start Telegov
$ npm run start:debug
$ npm run lint