Chatbot telegram with ibm cloud and IoT
This project shows how to make a chatbot on the telegram, reading data from the IoT platform of the IBM cloud system
[{"id":"242e757.8ff058a","type":"tab","label":"Chatboot c/ ESP","disabled":false,"info":""},{"id":"1208280b.537b98","type":"function","z":"242e757.8ff058a","name":"Conversão das informações","func":"context.flow.chatId = msg.payload.chatId;\ncontext.flow.type = msg.payload.type;\nmsg.payload = msg.payload.content;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":180,"wires":[["f8561dba.c239c"]]},{"id":"921eb51e.c6f618","type":"comment","z":"242e757.8ff058a","name":"Read.me","info":"1) Create a Watson Conversation on IBM Cloud (https://www.bluemix.net)\n2) Create a Telegram Bot:\n Open web.telegram.org\n find BotFather (contact)\n send /newbot\n Give a name for your bot (Botfather will ask it)\n Give a user name for it, which should have in the end \"Bot\"\n The BotFather will give you a token.\n ","x":360,"y":60,"wires":[]},{"id":"f3de4ee7.9d496","type":"comment","z":"242e757.8ff058a","name":"Read.me","info":"No lugar de Workspace ID colocar o Skill ID\n ","x":760,"y":120,"wires":[]},{"id":"6dd75218.c15b1c","type":"telegram receiver","z":"242e757.8ff058a","name":"","bot":"5485c65d.c921c8","saveDataDir":"","filterCommands":false,"x":330,"y":100,"wires":[["1208280b.537b98"],[]]},{"id":"33644b5b.a6cd24","type":"telegram sender","z":"242e757.8ff058a","name":"","bot":"5485c65d.c921c8","haserroroutput":false,"outputs":1,"x":1270,"y":160,"wires":[[]]},{"id":"d5c0fb17.11d908","type":"debug","z":"242e757.8ff058a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":300,"wires":[]},{"id":"7a28c339.9dd75c","type":"function","z":"242e757.8ff058a","name":"Declaração das variáveis","func":"context.global.temp = msg.payload.d.temperatura;\ncontext.global.tens = msg.payload.d.tensao;\ncontext.global.when = new Date();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":300,"wires":[["f9f88aed.f05b98"]]},{"id":"f8561dba.c239c","type":"watson-conversation-v1","z":"242e757.8ff058a","name":"Assistant","workspaceid":"29cf706e-c9e6-4f08-92c2-dd07f1305246","multiuser":false,"context":true,"empty-payload":false,"service-endpoint":"","timeout":"","optout-learning":false,"x":780,"y":180,"wires":[["293298a7.7821e8","d5c0fb17.11d908","72eccd3b.1c53e4"]]},{"id":"8234124b.017b1","type":"function","z":"242e757.8ff058a","name":"Parametrização das falhas","func":"var valor_temp;\n\nif (context.global.temp >30 )\n{\n msg.payload.chatId = \"1932609710\";\n msg.payload.type = \"message\";\n msg.payload.content= \"temperatura\"; \n}\n\n\nelse if (context.global.temp < 20 )\n{\n msg.payload.chatId = \"1932609710\";\n msg.payload.type = \"message\";\n msg.payload.content= \"temperatura\"; \n}\n\nif (context.global.tens >230 )\n{\n msg.payload.chatId = \"1932609710\";\n msg.payload.type = \"message\";\n msg.payload.content= \"tens\"; \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":180,"wires":[["1208280b.537b98"]]},{"id":"293298a7.7821e8","type":"function","z":"242e757.8ff058a","name":"Lógica das respostas","func":"msg.payload.chatId = context.flow.chatId;\nmsg.payload.type = context.flow.type\n\nif (msg.payload.output.text[0] == \"site\") msg.payload.content = \"https://victumtec.wixsite.com/project\" + \" Entenda como fui desenvolvido na aba de projetos!\";\n\nif (msg.payload.output.text[0] == \"oi\") msg.payload.content = \"Olá. Sou o Mano Tensão, como posso te ajudar?\";\n\nif (msg.payload.output.text[0] == \"pedido\") msg.payload.content = \"Qual informação deseja?\" ;\n\n\nif (msg.payload.output.text[0] == \"tensao\")\n { \n if (context.global.tens >= 230) msg.payload.content = \"Melhor verificar o que está acontecendo, tensão do motor está em torno de \" + [context.global.tens]+ \" °C\";\n \n else msg.payload.content = \"Tudo certo, tensão em torno de \" + [context.global.tens]+ \" Volts\";\n }\n\nif (msg.payload.output.text[0] == \"temperatura\")\n {\n if (context.global.temp >= 30) msg.payload.content = \"Melhor verificar o que está acontecendo, temperatura do motor está em torno de \" + [context.global.temp]+ \" °C\";\n \n else if (context.global.temp <= 22) msg.payload.content = \"Verifique se está tudo certo, temperatura está um pouco baixa em torno de \" + [context.global.temp]+ \" °C\";\n \n else msg.payload.content = \"Tudo certo, temperatura do motor está em torno de \" + [context.global.temp]+ \" °C\";\n }\n\nif (msg.payload.output.text[0] == \"obrigado\") msg.payload.content = \"Volte sempre que precisar :)\" ;\n\nif (msg.payload.output.text[0] == \"não entendi\") msg.payload.content = \"Eu não entendi. Você pode tentar reformular a frase\";\n\nif (msg.payload.output.text[0] == \"apresentacao\") msg.payload.content = \"Olá sou Mano Tensão, um chatboot criado pelo grupo de Manutenção 4.0 para auxiliá-lo na visualização de dados em tempo real ! \";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":180,"wires":[["1c125cf8.767ec3","33644b5b.a6cd24"]]},{"id":"88e326cb.0c2898","type":"ibmiot in","z":"242e757.8ff058a","authentication":"apiKey","apiKey":"e2eefa40.bbced8","inputType":"evt","logicalInterface":"","ruleId":"","deviceId":"","applicationId":"","deviceType":"Device1","eventType":"","commandType":"","format":"json","name":"IBM IoT","service":"registered","allDevices":true,"allApplications":"","allDeviceTypes":false,"allLogicalInterfaces":false,"allEvents":true,"allCommands":"","allFormats":true,"qos":0,"x":90,"y":300,"wires":[["7a28c339.9dd75c","8234124b.017b1"]]},{"id":"1c125cf8.767ec3","type":"debug","z":"242e757.8ff058a","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":300,"wires":[]},{"id":"f9f88aed.f05b98","type":"debug","z":"242e757.8ff058a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":300,"wires":[]},{"id":"72eccd3b.1c53e4","type":"function","z":"242e757.8ff058a","name":"Coleta do ID","func":"msg.payload.chatId = context.flow.chatId;\nmsg.payload.type = context.flow.type;\nmsg.payload.content = msg.payload.chatId;\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":950,"y":100,"wires":[[]]},{"id":"5485c65d.c921c8","type":"telegram bot","botname":"manotensaobot","usernames":"","chatids":"","baseapiurl":"","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","botpath":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false},{"id":"e2eefa40.bbced8","type":"ibmiot","name":"IoT","keepalive":"60","serverName":"","cleansession":true,"appId":"","shared":false}]