Git Product home page Git Product logo

d's Introduction

How to Create a Telegram Bot using QuickAlerts

Prerequisites


Step 1️⃣ - Creating the Bot on Telegram and adding it to a channel🤖

Open your Telegram app (Web/Desktop/Mobile) and search for @BotFather or go to https://t.me/BotFather. Open BotFather in Telegram and send a command /newbot in the chat, then give your bot a unique name for example, QuickAlerts Bot in the example below, then give it a username for example, myquickalert_bot in the example below. Once the BotFather creates your bot copy the username and the bot token.

Then create a new channel on Telegram, add a bot myidbot as administrator. Send a command /getgroupid, copy the id and then remove the bot. Refer animation below.

Now add your QuickAlerts Bot in this channel using the username.

At this point you should have the Token of your bot and channel ID of your channel.


Step 2️⃣ - Setting up the backend for bot🪛

Clone Example Monorepo

To begin, clone the qn-guide-examples repo, navigate to this project's directory, install dependencies and open the project directory in a code editor (VS code in this case).

git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/QuickAlerts/Telegram_bot
npm install
code .

Open a Terminal window and run ngrok on a port (make sure you have ngrok installed globally on your system).

ngrok http 5001

Copy the URL which you get after running the above command.

Now create a .env file in your /Telegram_bot directory and paste the following in it:

TOKEN=<bot_token>
PORT=5001

Replace <bot_token> with the bot token you got from BotFather in the last step. Make sure the value of PORT is exactly the same as the port number used with the ngrok command.

In the index.js file, replace <TELEGRAM_CHANNEL_ID> on line 24 with the channel ID you got from step 2.


Step 3️⃣ - Setting up QuickAlerts🔔

Setup an alert on the QuickAlerts dashboard, while setting up the WebHook in the dashboard use the URL you got from ngrok with a /webhook suffix. So it should look something like this https://31f5-2401-4900-1c96-acd1-501f-36bc-819c-c5f5.ngrok.io/webhook

Learn how to setup a QuickAlert: Guide, Video

An example QuickAlerts expression to get notified when ever a Bomber Hero NFT on Polygon chain is transfered:

(tx_logs_address == '0xd8a06936506379dbbe6e2d8ab1d8c96426320854') && (tx_logs_topic0 == '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef')

Step 4️⃣ - Running the bot🏃‍♂️💨

Open a new terminal window and run:

npm run dev

Now your Telegram channel should start recieving messages from the bot, the information in the messages is fed by QuickAlerts.

You can use/create different variables from line 17-20 and edit the message part in index.js file from line 28-29 based on the kind of information you want to display in the Telegram message. With QuickAlerts there is immense possibilities around the kind of alerts one can create.

Above and beyond!

d's People

Contributors

stepandra avatar

Watchers

 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.