UNPKG

node-red-contrib-telegrambot

Version:
1 lines 11.9 kB
[{"id":"bb54e2526165fae9","type":"telegram receiver","z":"89e16d21b4d07ec8","name":"","bot":"3b6bfbc0.423a04","saveDataDir":"","filterCommands":false,"x":190,"y":260,"wires":[["032a80f0b8a612c8","eb918922af9be44b"],[]]},{"id":"032a80f0b8a612c8","type":"function","z":"89e16d21b4d07ec8","name":"filter reply command","func":"var allowedChatId = -1001179754637;\nvar allowedUserIds = [138708568];\n\n// 1. Find out if we are in the correct chat and if the message was from admin\nvar fromChat = msg.payload.chatId;\nif(fromChat === allowedChatId && msg.originalMessage.from !== undefined) {\n\n var fromUser = msg.originalMessage.from.id;\n if(allowedUserIds.indexOf(fromUser) > -1) {\n \n // 2. Check if admin replied to a message\n var replyToMessage = msg.originalMessage.reply_to_message;\n var replyMessage = msg.originalMessage.text;\n if(replyToMessage !== undefined){\n\n // 3. take some action for user\n var userToHandle = replyToMessage.from.id;\n \n switch(replyMessage){\n case '/h':\n node.send([msg, null, null, null, null]);\n break;\n \n case '/d':\n node.send([null, msg, null, null, null]);\n break;\n \n case '/p':\n node.send([null, null, msg, null, null]);\n break;\n \n case '/r':\n node.send([null, null, null, msg, null]);\n break;\n \n default:\n node.send([null, null, null, null, msg]);\n break;\n }\n }\n }\n}","outputs":5,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":260,"wires":[["6a2ed5e1f29765b7"],["d6461c4d70cafd39"],["5494e1452bbf7bed"],["6c7f8a0a02dd99e5"],["321bb3180279417f"]],"icon":"node-red/switch.svg"},{"id":"6a2ed5e1f29765b7","type":"function","z":"89e16d21b4d07ec8","name":"/h hello","func":"// see also https://core.telegram.org/bots/api#sendmessage\n\nvar user = msg.originalMessage.reply_to_message.from.username;\nvar messageId = msg.originalMessage.reply_to_message.message_id;\nmsg.payload.type = 'message';\nmsg.payload.content = \"hello \" + user;\nmsg.payload.options = {\n reply_to_message_id : messageId\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":240,"wires":[["a65f7c544195fe5f"]],"icon":"font-awesome/fa-info"},{"id":"c701baf734debe32","type":"telegram sender","z":"89e16d21b4d07ec8","name":"","bot":"3b6bfbc0.423a04","haserroroutput":false,"outputs":1,"x":1470,"y":260,"wires":[[]]},{"id":"d6461c4d70cafd39","type":"function","z":"89e16d21b4d07ec8","name":"/d delete message","func":"// see also https://core.telegram.org/bots/api#deletemessage\n\nvar messageId = msg.originalMessage.reply_to_message.message_id;\nmsg.payload.type = 'deleteMessage';\nmsg.payload.content = messageId;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":280,"wires":[["a65f7c544195fe5f"]],"icon":"font-awesome/fa-trash-o"},{"id":"a65f7c544195fe5f","type":"telegram sender","z":"89e16d21b4d07ec8","name":"","bot":"3b6bfbc0.423a04","haserroroutput":false,"outputs":1,"x":1010,"y":260,"wires":[["64b4c132328952aa"]]},{"id":"64b4c132328952aa","type":"function","z":"89e16d21b4d07ec8","name":"delete command message","func":"// this lets vanish the command issued by the admin\n// if you do not need it you can remove this function node \n// and the following call to the sender node, too.\n\nvar messageId = msg.originalMessage.message_id;\nmsg.payload.type = 'deleteMessage';\nmsg.payload.content = messageId;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":260,"wires":[["c701baf734debe32"]],"icon":"font-awesome/fa-trash"},{"id":"9ff372dc9a121061","type":"comment","z":"89e16d21b4d07ec8","name":"SuperGroup Admin Example","info":"Example flow for demonstration how to handle replies to messages sent by user to issue admin actions.\n\nRight click on a message of a user and reply to that message using one of the predefined example command:\n- /h for hello echo\n- /d for deleting a message\n- /p to make user admin\n- /r to make admin a normal user\n- \nNote that the allowed users and super groups are right now hard coded in the \"filter replay command\" node. This can be changed or removed.","x":200,"y":180,"wires":[]},{"id":"5494e1452bbf7bed","type":"function","z":"89e16d21b4d07ec8","name":"/p promote user","func":"// see also https://core.telegram.org/bots/api#promotechatmember\n\n// Note that it makes adifference if you are in a channel or group or super group.\n// whenever you get an exception saying RIGHT_FORBIDDEN, then make sure that only valid fields are set.\n// This example is tested with super group and hence can_post_messages and can_edit_messages are not set.\n\nvar user = msg.originalMessage.reply_to_message.from.id;\nmsg.payload.type = 'promoteChatMember';\nmsg.payload.content = user;\nmsg.payload.options = {\n is_anonymous : false, // Pass True, if the administrator's presence in the chat is hidden\n can_manage_chat\t: true, //\tPass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege\n // can_post_messages : true, // Pass True, if the administrator can create channel posts, channels only\n // can_edit_messages : true, // Pass True, if the administrator can edit messages of other users and can pin messages, channels only\n can_delete_messages\t: true, // Pass True, if the administrator can delete messages of other users\n can_manage_voice_chats : true,// Pass True, if the administrator can manage voice chats\n can_restrict_members : true, // Pass True, if the administrator can restrict, ban or unban chat members\n can_promote_members\t: true, // Pass True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)\n can_change_info\t: true, // Pass True, if the administrator can change chat title, photo and other settings\n can_invite_users : true, // Pass True, if the administrator can invite new users to the chat\n can_pin_messages : true, // Pass True, if the administrator can pin messages, supergroups only \n};\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":340,"wires":[["a65f7c544195fe5f"]]},{"id":"6c7f8a0a02dd99e5","type":"function","z":"89e16d21b4d07ec8","name":"/r restrict user","func":"var user = msg.originalMessage.reply_to_message.from.id;\nmsg.payload.type = 'restrictChatMember';\nmsg.payload.content = user;\nmsg.payload.options = {\n can_send_messages : false, // Optional. True, if the user is allowed to send text messages, contacts, locations and venues\n can_send_media_messages : false, // Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages\n can_send_polls : false, // Optional. True, if the user is allowed to send polls, implies can_send_messages\n can_send_other_messages\t: false, // Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages\n can_add_web_page_previews : false, // Optional. True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages\n can_change_info : false, // Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups\n can_invite_users : false, // Optional. True, if the user is allowed to invite new users to the chat\n can_pin_messages : false, // Optional. True, if the user is allowed to pin messages. Ignored in public supergroups \n};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":380,"wires":[["a65f7c544195fe5f"]]},{"id":"321bb3180279417f","type":"debug","z":"89e16d21b4d07ec8","name":"unknown command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":440,"wires":[]},{"id":"fc8a634a58030601","type":"telegram event","z":"89e16d21b4d07ec8","name":"","bot":"3b6bfbc0.423a04","event":"my_chat_member","autoanswer":false,"x":430,"y":740,"wires":[["7cb1c5d5dd2e463e"]]},{"id":"0d429424f9a6204a","type":"comment","z":"89e16d21b4d07ec8","name":"Bot Status Changed","info":"Optional. The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.\n\nsee https://core.telegram.org/bots/api#update","x":430,"y":700,"wires":[]},{"id":"eb918922af9be44b","type":"function","z":"89e16d21b4d07ec8","name":"filter for specific events","func":"var type = msg.payload.type;\nswitch(type){\n case 'new_chat_members':\n node.send([msg, null, null]);\n break;\n \n case 'left_chat_member':\n node.send([null, msg, null]);\n break;\n \n default:\n node.send([null, null, msg]);\n break;\n}","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":600,"wires":[["18f1f7b38fc29892"],["1f6715997fbf0d59"],[]],"icon":"node-red/switch.svg"},{"id":"18f1f7b38fc29892","type":"function","z":"89e16d21b4d07ec8","name":"new chat members","func":"// see also https://core.telegram.org/bots/api#user\n\nvar users = msg.payload.content;\n\nfor (const user of users) {\n var name = user.first_name;\n msg.payload.type = 'message';\n msg.payload.content = \"hello \" + name;\n node.send([msg]);\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":580,"wires":[["7cb1c5d5dd2e463e","bfda6a4b2b3f555e"]],"icon":"font-awesome/fa-info"},{"id":"1f6715997fbf0d59","type":"function","z":"89e16d21b4d07ec8","name":"left chat members","func":"// see also https://core.telegram.org/bots/api#user\n\nvar user = msg.payload.user;\n\nvar name = user.first_name;\nmsg.payload.type = 'message';\nmsg.payload.content = \"bye \" + name;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":620,"wires":[["7cb1c5d5dd2e463e","bfda6a4b2b3f555e"]],"icon":"font-awesome/fa-info"},{"id":"5e5990d5ba0f143c","type":"debug","z":"89e16d21b4d07ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":700,"wires":[]},{"id":"7cb1c5d5dd2e463e","type":"function","z":"89e16d21b4d07ec8","name":"optional log here","func":"// Here you could log your events.\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":700,"wires":[["5e5990d5ba0f143c"]],"icon":"font-awesome/fa-file-text-o"},{"id":"bfda6a4b2b3f555e","type":"telegram sender","z":"89e16d21b4d07ec8","name":"","bot":"3b6bfbc0.423a04","haserroroutput":false,"outputs":1,"x":1010,"y":580,"wires":[[]]},{"id":"3b6bfbc0.423a04","type":"telegram bot","botname":"HeinzBot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]