Sergio
Published © GPL3+

Telegram Bot to control LightBlue Bean

This tutorial teaches you how to create a telegram bot to control LightBlue Bean RGB led.

IntermediateFull instructions provided2 hours1,613
Telegram Bot to control LightBlue Bean

Things used in this project

Story

Read more

Code

Node-Red flow

JSON
[{"id":"6aced179.95313","type":"bean","z":"eeddf882.112208","name":"Bean","uuid":"","connectiontype":"constant","connectiontimeout":"0"},{"id":"e1f88521.1e0778","type":"telegram bot","z":"eeddf882.112208","botname":"fooBot","usernames":"[]","chatids":"[]"},{"id":"b2223fa6.4dddc","type":"telegram bot","z":"eeddf882.112208","botname":"fooBot","usernames":"[]","chatids":"[]"},{"id":"2f3b733d.d0c48c","type":"telegram command","z":"eeddf882.112208","name":"/help","command":"/help","bot":"b2223fa6.4dddc","x":126,"y":337,"wires":[["caf6342e.3509c8"],[]]},{"id":"caf6342e.3509c8","type":"function","z":"eeddf882.112208","name":"Help","func":"var help = \"/help - shows help information\\r\\n\";\nhelp += \"/setcolor - set color of Bean\\r\\n\";\n\nmsg.payload.content = help;\nreturn msg;","outputs":1,"noerr":0,"x":417,"y":333,"wires":[["56de0417.a921fc"]]},{"id":"56de0417.a921fc","type":"telegram sender","z":"eeddf882.112208","name":"","bot":"e1f88521.1e0778","x":794,"y":159,"wires":[[]]},{"id":"7da49416.825b6c","type":"telegram command","z":"eeddf882.112208","name":"/setcolor","command":"/setcolor","bot":"","x":133,"y":228,"wires":[["8b484ef2.74b7b"],["d16cab88.2e9358","f08b686b.0f7498"]]},{"id":"8b484ef2.74b7b","type":"function","z":"eeddf882.112208","name":"confirmation message","func":"context.global.keyboard = { pending : true };\ncontext.global.color = { pending : true };\n\nvar opts = {\n  reply_to_message_id: msg.payload.messageId,\n  reply_markup: JSON.stringify({\n    keyboard: [['Red','Blue'],['Green','Off']],\n      'resize_keyboard' : true, \n      'one_time_keyboard' : true\n  })\n};\n\nmsg.payload.content = 'Choose color';\nmsg.payload.options = opts;\n\nreturn [ msg ];\n","outputs":"1","noerr":0,"x":399.5,"y":126,"wires":[["56de0417.a921fc"]]},{"id":"d16cab88.2e9358","type":"function","z":"eeddf882.112208","name":"create response","func":"if(context.global.keyboard.pending)\n{\n    context.global.keyboard.pending = false;\n    \n    if(msg.payload.content === 'Red')\n    {\n        msg.payload.content = 'Bean set to Red';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Blue')\n    {\n        msg.payload.content = 'Bean set to Red';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Green')\n    {\n        msg.payload.content = 'Bean set to Green';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Off')\n    {\n        msg.payload.content = 'Bean off';\n        return msg;   \n    }\n}\n","outputs":"1","noerr":0,"x":392.5,"y":183,"wires":[["56de0417.a921fc"]]},{"id":"f08b686b.0f7498","type":"function","z":"eeddf882.112208","name":"set color","func":"if(context.global.color.pending)\n{\n    context.global.color.pending = false;\n    \n    if(msg.payload.content === 'Red')\n    {\n        msg.payload = '255,0,0';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Blue')\n    {\n        msg.payload = '0,0,255';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Green')\n    {\n        msg.payload = '0,255,0';\n        return msg;   \n    }\n    else if(msg.payload.content === 'Off')\n    {\n        msg.payload = 'off';\n        return msg;   \n    }\n}\n","outputs":1,"noerr":0,"x":386,"y":237,"wires":[["ac4dc1f2.53b24"]]},{"id":"ac4dc1f2.53b24","type":"bean led","z":"eeddf882.112208","name":"","bean":"6aced179.95313","x":795,"y":248,"wires":[]}]

Credits

Sergio

Sergio

1 project • 2 followers

Comments