const { registerJoystreamTypes } = require('@joystream/types'); const { ApiPromise, WsProvider } = require('@polkadot/api'); const TelegramBot = require('node-telegram-bot-api'); // replace the value below with the Telegram token you receive from @BotFather const token = 'yourowntoken'; // Create a bot that uses 'polling' to fetch new updates const bot = new TelegramBot(token); //get chat id here https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id const chatid = 'yourownchat'; async function main () { registerJoystreamTypes() // Create the API and wait until ready const api = await ApiPromise.create({ provider: new WsProvider() }) let lastchannelnotif = await getcurrentChannelId(api) //let lastchannelnotif = 25 const unsubscribe = await api.rpc.chain.subscribeNewHeads(async (header) => { const currentchannelid = await getcurrentChannelId(api) console.log('Latest channelid is :',currentchannelid) if (currentchannelid>lastchannelnotif) { const newchannel = [] for (lastchannelnotif+1;lastchannelnotifNew channel id created:${lastchannelnotif+1}\r\nChannel Title: ${channeltitle}\r\nMember ID: ${memberid}\r\nMember Handler: ${channelownerhandler}`) } bot.sendMessage(chatid, newchannel.join("\r\n\r\n"), { parse_mode: 'html' }) } }) } const getmemberHandle = async (api,memberid) => { const memberprofile = await api.query.members.memberProfile(memberid) const handler = memberprofile.raw.handle.toJSON() return handler } const getcurrentChannelId = async (api) => { const nextchannelid = await api.query.contentWorkingGroup.nextChannelId() const currentchannelid = nextchannelid.toNumber()-1 return currentchannelid } main()