Skip to content

Instantly share code, notes, and snippets.

@brunoamaral
Created May 28, 2021 13:07
Show Gist options
  • Save brunoamaral/e709c671607681112253f5b78a018ca0 to your computer and use it in GitHub Desktop.
Save brunoamaral/e709c671607681112253f5b78a018ca0 to your computer and use it in GitHub Desktop.
Node-Red flow for a telegram bot that adds tasks to Notion.so
[
{
"id": "2dec1e89.a9a582",
"type": "chatbot-telegram-receive",
"z": "b05ba402.a21508",
"bot": "21c9917c.15264e",
"botProduction": "21c9917c.15264e",
"x": 170,
"y": 640,
"wires": [
[
"9b377880.dbe808"
]
]
},
{
"id": "9b377880.dbe808",
"type": "chatbot-command",
"z": "b05ba402.a21508",
"name": "",
"command": "/todo",
"x": 330,
"y": 640,
"wires": [
[
"175f8cc9.bfd623"
]
]
},
{
"id": "175f8cc9.bfd623",
"type": "function",
"z": "b05ba402.a21508",
"name": "",
"func": "var data = msg.payload.arguments\nvar title = data.join(\" \")\nvar context;\nvar client;\nfor (var key in data) {\n if (Object.hasOwnProperty.call(data, key)) {\n value = data[key]\n if (value.startsWith(\"@\")) {\n context = value.replace(\"@\", \"\");\n }\n if (value.startsWith(\"#\")) {\n client = value.replace(\"#\",\"\");\n }\n \n }\n}\n\nvar postData = {\n\t\"parent\": { \"database_id\": \"c9edd199-bb22-4fbb-9a86-a09f5ad12718\" },\n\t\"properties\": {\n\t\t\"Name\": {\n\t\t\t\"title\": [\n\t\t\t\t{\n\t\t\t\t\t\"text\": {\n\t\t\t\t\t\t\"content\": title.replace(\"@\"+context,\"\").replace(\"#\"+client,\"\")\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t],\n\t\t},\n\t\t\"Status\": {\n\t\t \"select\": {\n\t\t \"name\": \"To Do\"\n\t\t }\n\t\t}\n\t\t\n}}\n\n\nif ( typeof context !== \"undefined\"){\n postData.properties.Context = {\"select\":{\"name\":context}}\n}\nif ( typeof client !== \"undefined\"){\n postData.properties.Client = {\"select\":{\"name\":client}}\n}\n\n//\t\t\"Context\": {\n//\t\t\t\"select\": {\n//\t\t\t\t\"name\": context\n//\t\t\t}\n//\t\t},\n//\t\t\"Client\": {\n//\t\t \"select\": {\n//\t\t \"name\": client\n//\t\t }\n//\t\t}\n\nmsg.payload = postData\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 480,
"y": 640,
"wires": [
[
"88eba1fe.99b69"
]
]
},
{
"id": "88eba1fe.99b69",
"type": "http request",
"z": "b05ba402.a21508",
"name": "create page",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://api.notion.com/v1/pages",
"tls": "e3876559.c845b8",
"persist": false,
"proxy": "",
"authType": "bearer",
"x": 650,
"y": 640,
"wires": [
[
"d79e2f0e.bce56"
]
]
},
{
"id": "672cf87.6b58508",
"type": "chatbot-message",
"z": "b05ba402.a21508",
"name": "",
"message": [
{
"message": "{{payload.url}}\n"
}
],
"language": "",
"x": 1110,
"y": 640,
"wires": [
[
"28b95ec6.ac5592"
]
]
},
{
"id": "28b95ec6.ac5592",
"type": "chatbot-telegram-send",
"z": "b05ba402.a21508",
"bot": "21c9917c.15264e",
"botProduction": "21c9917c.15264e",
"track": false,
"passThrough": false,
"outputs": 0,
"x": 1270,
"y": 640,
"wires": []
},
{
"id": "d79e2f0e.bce56",
"type": "json",
"z": "b05ba402.a21508",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 790,
"y": 640,
"wires": [
[
"3db663e4.81d6fc"
]
]
},
{
"id": "3db663e4.81d6fc",
"type": "change",
"z": "b05ba402.a21508",
"name": "",
"rules": [
{
"t": "set",
"p": "payload.url",
"pt": "msg",
"to": "\"https://notion.so/\" & $replace(payload.id,\"-\",\"\")",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 950,
"y": 640,
"wires": [
[
"672cf87.6b58508"
]
]
},
{
"id": "21c9917c.15264e",
"type": "chatbot-telegram-node",
"botname": "Johny Five",
"usernames": "amaralb,1116128351",
"providerToken": "",
"polling": "1000",
"store": "510c9c14.f3eb74",
"log": "",
"debug": false,
"webHook": "",
"connectMode": "polling"
},
{
"id": "e3876559.c845b8",
"type": "tls-config",
"name": "",
"cert": "",
"key": "",
"ca": "",
"certname": "node-cert.pem",
"keyname": "node-key.pem",
"caname": "",
"servername": "",
"verifyservercert": true
},
{
"id": "510c9c14.f3eb74",
"type": "chatbot-context-store",
"name": "johnny-context",
"contextStorage": "memory",
"contextParams": ""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment