Telegram
Telegram is one of the most popular chat platforms, and is great to build bots and notifications when things happen on chain.
Setup a bot on telegram
You have to use telegram itself to setup a bot:
- Search BotFather on Telegram.
- Type /start to get started.
- Type /newbot to get a bot.
- Enter your Bot name and unique Username, which should end with the bot.
- Then, you will get your Bot token. (keep this safe you need it shortly)
Configure rindexer
telegram
property accepts an array allowing you to split up the chats any way you wish.
Example
name: RocketPoolETHIndexer
description: My first rindexer project
repository: https://github.com/joshstevens19/rindexer
project_type: no-code
networks:
- name: ethereum
chain_id: 1
rpc: https://mainnet.gateway.tenderly.co
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
# conditions are optional
conditions:
- "from": "0x0338ce5020c447f7e668dc2ef778025ce3982662||0x0338ce5020c447f7e668dc2ef778025ce398266u"
- "value": ">=10||<=2000000000000000000"
template_inline: "*New RETH Transfer Event*
from: {{from}}
to: {{to}}
amount: {{format_value(value, 18)}}
RETH contract: {{transaction_information.address}}
[etherscan](https://etherscan.io/tx/{{transaction_information.transaction_hash}})
"
bot_token
This is your telegram bot token which you generate using @BotFather.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id
You have add your bot to chats to use it, so this is the chat ID you wish the bot to send messages to.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks
This is an array of networks you want to send messages to this telegram chat.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages
This is an array of messages you want to send to this telegram chat. It is an array as you can define many different messages to send to this chat with different conditions.
event_name
This is the name of the event you want to send a message for, must match the ABI event name.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
conditions
This accepts an array of conditions you want to apply to the event data before sending a message to this telegram chat.
You may want to filter on the message based on the event data, if the event data has not got an index on the on the
solidity event you can not filter it over the logs. The conditions
filter is here to help you with this,
based on your ABI you can filter on the event data.
rindexer has enabled a special syntax which allows you to define on your ABI fields what you want to filter on.
>
- higher then (for numbers only)<
- lower then (for numbers only)=
- equals>=
- higher then or equals (for numbers only)<=
- lower then or equals (for numbers only)||
- or&&
- and
So lets look at an example lets say i only want to get transfer events which are higher then 2000000000000000000
RETH wei
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
conditions:
- "value": ">=2000000000000000000"
We use the ABI input name value
to filter on the value field, you can find these names in the ABI file.
{
"anonymous":false,
"inputs":[
{
"indexed":true,
"internalType":"address",
"name":"from",
"type":"address"
},
{
"indexed":true,
"internalType":"address",
"name":"to",
"type":"address"
},
{
"indexed":false,
"internalType":"uint256",
"name":"value",
"type":"uint256"
}
],
"name":"Transfer",
"type":"event"
}
You can use the ||
or &&
to combine conditions.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
conditions:
- "value": ">=2000000000000000000 && value <=4000000000000000000"
You can use the =
to filter on other aspects like the from
or to
address.
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
conditions:
- "from": "0x0338ce5020c447f7e668dc2ef778025ce3982662 || 0x0338ce5020c447f7e668dc2ef778025ce398266u"
- "value": ">=2000000000000000000 || value <=4000000000000000000"
If you have a tuple and you want to get that value you just use the object notation.
For example lets say we want to only get the events for profileId
from the quoteParams
tuple which equals 1
:
{
"anonymous": false,
"inputs": [
{
"components": [
{
"internalType": "uint256",
"name": "profileId",
"type": "uint256"
},
...
],
"indexed": false,
"internalType": "struct Types.QuoteParams",
"name": "quoteParams",
"type": "tuple"
},
...
],
"name": "QuoteCreated",
"type": "event"
}
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
conditions:
- "quoteParams.profileId": "=1"
template_inline
You can then write your own template inline, this is the template you want to send to the chat.
You have to use the ABI input names in object notation for example if i wanted to put value in the template
i just have to write {{value}}
in the template and it will be replaced with the value of the event itself.
The template supports:
- bold text = *bold text*
- italic text = _italic text_
- inline url = [inline URL](YOUR_URL)
- inline fixed-width code = `inline fixed-width code`
- pre-formatted fixed-width code block = ```pre-formatted fixed-width code block```
- pre-formatted fixed-width known code block = ```rust pre-formatted fixed-width known code block```
- breaks = just line break in the template
transaction_information
You also can use the transaction_information
object to get common information about the transaction, this is the
transaction information for the event.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TxInformation {
pub network: String,
// This will convert to a hex string in the template
pub address: Address,
// This will convert to a hex string in the template
pub block_hash: H256,
// This will convert to a string decimal in the template
pub block_number: U64,
// This will convert to a hex string in the template
pub transaction_hash: H256,
// This will convert to a string decimal in the template
pub log_index: U256,
// This will convert to a string decimal in the template
pub transaction_index: U64,
}
format_value
You can use the format_value
function to format the value of the event to a decimal value with the specified decimals.
Lets put it all together:
...
contracts:
- name: RocketPoolETH
details:
- network: ethereum
address: "0xae78736cd615f374d3085123a210448e74fc6393"
start_block: "18600000"
end_block: "18600181"
abi: "./abis/RocketTokenRETH.abi.json"
include_events:
- Transfer
chat:
telegram:
- bot_token: ${TELEGRAM_BOT_TOKEN}
chat_id: -4223616270
networks:
- ethereum
messages:
- event_name: Transfer
template_inline: "*New RETH Transfer Event*
from: {{from}}
to: {{to}}
amount: {{format_value(value, 18)}}
RETH contract: {{transaction_information.address}}
[etherscan](https://etherscan.io/tx/{{transaction_information.transaction_hash}})
"