Skip to content

Instantly share code, notes, and snippets.

@cerebrate
Created May 12, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cerebrate/c98b2d04b823816e2ab04baaaf139942 to your computer and use it in GitHub Desktop.
Save cerebrate/c98b2d04b823816e2ab04baaaf139942 to your computer and use it in GitHub Desktop.
A flow to integrate Mattermost and Home Assistant Assist.
[
{
"id": "a40d0f65c38c036e",
"type": "comment",
"z": "7e65c3881fee1899",
"name": "Incoming message processing",
"info": "",
"x": 160,
"y": 40,
"wires": []
},
{
"id": "5cb95fc33972f493",
"type": "change",
"z": "7e65c3881fee1899",
"name": "format for conversation API",
"rules": [
{
"t": "set",
"p": "original",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"data\":{\"language\":\"en\"}}",
"tot": "json"
},
{
"t": "set",
"p": "payload.data.text",
"pt": "msg",
"to": "original",
"tot": "msg"
},
{
"t": "delete",
"p": "original",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1140,
"y": 100,
"wires": [
[
"c56b875f094c6da1"
]
]
},
{
"id": "b99d0d2169adb22f",
"type": "ha-api",
"z": "7e65c3881fee1899",
"name": "Assist API",
"server": "aeb8ddd83e01cc39",
"version": 1,
"debugenabled": false,
"protocol": "http",
"method": "post",
"path": "/api/conversation/process",
"data": "msg",
"dataType": "jsonata",
"responseType": "json",
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "results"
}
],
"x": 540,
"y": 280,
"wires": [
[
"ecb24f7cd3a06b5e",
"f81d4f16966d63f9"
]
]
},
{
"id": "64ad0f9befe7ee96",
"type": "api-current-state",
"z": "7e65c3881fee1899",
"name": "if_not_disconnected",
"server": "aeb8ddd83e01cc39",
"version": 3,
"outputs": 2,
"halt_if": "false",
"halt_if_type": "bool",
"halt_if_compare": "is",
"entity_id": "input_boolean.bot_disconnect",
"state_type": "habool",
"blockInputOverrides": false,
"outputProperties": [],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 880,
"y": 100,
"wires": [
[
"5cb95fc33972f493"
],
[
"a2536d6c1bee9511"
]
]
},
{
"id": "ecb24f7cd3a06b5e",
"type": "switch",
"z": "7e65c3881fee1899",
"name": "",
"property": "payload.response.response_type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "action_done",
"vt": "str"
},
{
"t": "eq",
"v": "query_answer",
"vt": "str"
},
{
"t": "eq",
"v": "error",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 170,
"y": 440,
"wires": [
[
"f8e34e7c8249c480",
"e8c72f8a4959f2f1"
],
[
"f8e34e7c8249c480",
"e8c72f8a4959f2f1"
],
[
"f8e34e7c8249c480",
"e8c72f8a4959f2f1"
]
]
},
{
"id": "047153482113d7c3",
"type": "comment",
"z": "7e65c3881fee1899",
"name": "Handle response",
"info": "",
"x": 160,
"y": 360,
"wires": []
},
{
"id": "e247409e59331a6e",
"type": "comment",
"z": "7e65c3881fee1899",
"name": "stash conversation_id",
"info": "",
"x": 400,
"y": 400,
"wires": []
},
{
"id": "f8e34e7c8249c480",
"type": "switch",
"z": "7e65c3881fee1899",
"name": "not null",
"property": "payload.response.conversation_id",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 360,
"y": 440,
"wires": [
[
"632916822c7c9ed0"
]
]
},
{
"id": "632916822c7c9ed0",
"type": "change",
"z": "7e65c3881fee1899",
"name": "save id",
"rules": [
{
"t": "set",
"p": "current_conversation",
"pt": "flow",
"to": "payload.response.conversation_id",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 520,
"y": 440,
"wires": [
[
"9bb2b26821549fd1"
]
]
},
{
"id": "c56b875f094c6da1",
"type": "switch",
"z": "7e65c3881fee1899",
"name": "",
"property": "current_conversation_time",
"propertyType": "flow",
"rules": [
{
"t": "nnull"
},
{
"t": "else"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 130,
"y": 280,
"wires": [
[
"c7c950282aba638d"
],
[
"b99d0d2169adb22f"
]
]
},
{
"id": "9bb2b26821549fd1",
"type": "trigger",
"z": "7e65c3881fee1899",
"name": "",
"op1": "false",
"op2": "true",
"op1type": "bool",
"op2type": "bool",
"duration": "30",
"extend": true,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 2,
"x": 730,
"y": 440,
"wires": [
[],
[
"3ae2c472da921925"
]
]
},
{
"id": "3ae2c472da921925",
"type": "change",
"z": "7e65c3881fee1899",
"name": "null id",
"rules": [
{
"t": "set",
"p": "current_conversation",
"pt": "flow",
"to": "null",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 890,
"y": 440,
"wires": [
[]
]
},
{
"id": "c7c950282aba638d",
"type": "change",
"z": "7e65c3881fee1899",
"name": "set conversation_id",
"rules": [
{
"t": "set",
"p": "payload.data.conversation_id",
"pt": "msg",
"to": "current_conversation",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 240,
"wires": [
[
"b99d0d2169adb22f"
]
]
},
{
"id": "f246b7438515ce13",
"type": "comment",
"z": "7e65c3881fee1899",
"name": "Respond with speech",
"info": "",
"x": 400,
"y": 520,
"wires": []
},
{
"id": "e8c72f8a4959f2f1",
"type": "change",
"z": "7e65c3881fee1899",
"name": "extract speech response",
"rules": [
{
"t": "set",
"p": "tmp",
"pt": "msg",
"to": "payload.response.speech.plain.speech",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"username\":\"Jeeves\",\"icon_emoji\":\"bot-mamiya\"}",
"tot": "json"
},
{
"t": "set",
"p": "payload.text",
"pt": "msg",
"to": "tmp",
"tot": "msg"
},
{
"t": "delete",
"p": "tmp",
"pt": "msg"
},
{
"t": "set",
"p": "rejectUnauthorized",
"pt": "msg",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 410,
"y": 580,
"wires": [
[
"073d45d0453c963b"
]
]
},
{
"id": "f81d4f16966d63f9",
"type": "debug",
"z": "7e65c3881fee1899",
"name": "api-out",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 730,
"y": 220,
"wires": []
},
{
"id": "bd2fd2f2dc611ac5",
"type": "http in",
"z": "7e65c3881fee1899",
"name": "",
"url": "/jeeves-assist",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 160,
"y": 100,
"wires": [
[
"e4a9cc55fde0c1d9"
]
]
},
{
"id": "3162e33d9f1cd691",
"type": "debug",
"z": "7e65c3881fee1899",
"name": "web-in",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 650,
"y": 40,
"wires": []
},
{
"id": "073d45d0453c963b",
"type": "http response",
"z": "7e65c3881fee1899",
"name": "Success!",
"statusCode": "200",
"headers": {},
"x": 620,
"y": 580,
"wires": []
},
{
"id": "e4a9cc55fde0c1d9",
"type": "switch",
"z": "7e65c3881fee1899",
"name": "Validate token",
"property": "payload.token",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "TOKEN",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 420,
"y": 100,
"wires": [
[
"3162e33d9f1cd691",
"4e7eb8e11801d8d6"
],
[
"81c48c07bcfc400c"
]
]
},
{
"id": "81c48c07bcfc400c",
"type": "http response",
"z": "7e65c3881fee1899",
"name": "Forbidden",
"statusCode": "401",
"headers": {},
"x": 660,
"y": 160,
"wires": []
},
{
"id": "4e7eb8e11801d8d6",
"type": "change",
"z": "7e65c3881fee1899",
"name": "strip to text",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.text",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 100,
"wires": [
[
"64ad0f9befe7ee96"
]
]
},
{
"id": "a2536d6c1bee9511",
"type": "http response",
"z": "7e65c3881fee1899",
"name": "Service Unavailable",
"statusCode": "503",
"headers": {},
"x": 1120,
"y": 160,
"wires": []
},
{
"id": "aeb8ddd83e01cc39",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": 30,
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": true
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment