{ "kind": "open-flow-workflow", "version": 1, "name": "WooCommerce Order to Mattermost", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_7e3e6783638f5afe": { "name": "Order created", "kind": "integration", "config": { "events": { "kind": "value", "value": [ "order.created" ] }, "webhookName": { "kind": "value", "value": "Mattermost order notice" } }, "definition": { "configInputs": [ { "jsonSchema": { "type": "array", "items": { "type": "string", "enum": [ "coupon.created", "coupon.updated", "coupon.deleted", "coupon.restored", "customer.created", "customer.updated", "customer.deleted", "order.created", "order.updated", "order.deleted", "order.restored", "product.created", "product.updated", "product.deleted", "product.restored", "product.published" ] }, "minItems": 1, "maxItems": 16, "uniqueItems": true }, "nullable": false, "handle": "events" }, { "jsonSchema": { "type": "string", "minLength": 1, "maxLength": 120 }, "nullable": false, "handle": "webhookName", "value": "OOMOL Trigger" } ], "definitionVersion": 2, "description": "Triggers when selected WooCommerce store events occur.", "displayName": "Store Event", "key": "woocommerce.on_store_event", "name": "on_store_event", "outputs": [ { "jsonSchema": { "type": "object" }, "nullable": false, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "deliveryId" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "event" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "resource" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "source" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "topic" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "webhookId" } ], "provider": "woocommerce", "type": "integration", "endpoint": { "body": { "allowArray": false, "allowEmpty": false, "formats": [ "json" ] }, "methods": [ "POST" ], "successStatus": 202 } } }, "n_44a49850f9437a9d": { "inputs": { "order": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7e3e6783638f5afe", "output": "body" } ] }, "channelId": { "kind": "value", "value": "YOUR_MATTERMOST_CHANNEL_ID" } }, "name": "Build the purchase notice", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "order" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "channelId" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "order" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "channelId" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "message" } ], "name": "Build the purchase notice", "moduleId": "n_2a339c9420a23c05", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_998a598ebbfe3a17": { "inputs": { "channelId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_44a49850f9437a9d", "output": "channelId" } ] }, "message": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_44a49850f9437a9d", "output": "message" } ] }, "props": { "kind": "value", "value": { "attachments": [] } } }, "name": "Post the purchase notice", "kind": "task", "task": { "inputs": [ { "description": "A Mattermost object ID.", "jsonSchema": { "type": "string", "minLength": 1, "description": "A Mattermost object ID." }, "nullable": false, "handle": "channelId" }, { "description": "The Markdown message body to post.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The Markdown message body to post." }, "nullable": false, "handle": "message" }, { "description": "Optional root post ID for replying in a thread.", "jsonSchema": { "type": "string", "minLength": 1, "description": "Optional root post ID for replying in a thread." }, "nullable": true, "handle": "rootId", "value": null }, { "description": "Optional Mattermost post props object.", "jsonSchema": { "type": "object", "properties": {}, "additionalProperties": true, "description": "Optional Mattermost post props object." }, "nullable": true, "handle": "props", "value": null } ], "outputs": [ { "description": "A Mattermost post object.", "jsonSchema": { "type": "object", "properties": {}, "additionalProperties": true, "description": "A Mattermost post object." }, "nullable": false, "handle": "post" }, { "description": "The raw Mattermost API JSON response.", "jsonSchema": { "description": "The raw Mattermost API JSON response." }, "nullable": false, "handle": "raw" } ], "name": "Post the purchase notice", "executor": { "kind": "connector", "action": "mattermost.create_post" } } }, "n_257aef29795246ec": { "inputs": { "order": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_44a49850f9437a9d", "output": "order" } ] }, "channelId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_44a49850f9437a9d", "output": "channelId" } ] }, "message": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_44a49850f9437a9d", "output": "message" } ] }, "post": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_998a598ebbfe3a17", "output": "post" } ] }, "rawPost": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_998a598ebbfe3a17", "output": "raw" } ] } }, "name": "Confirm the purchase notice", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "order" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "channelId" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "message" }, { "jsonSchema": { "type": "object", "properties": {}, "additionalProperties": true, "description": "A Mattermost post object." }, "nullable": false, "handle": "post" }, { "jsonSchema": { "description": "The raw Mattermost API JSON response." }, "nullable": false, "handle": "rawPost" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "order" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "post" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "rawPost" } ], "name": "Confirm the purchase notice", "moduleId": "n_64e956ce59302dbc", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_7750a141afbdac3d": { "name": "Order and posted notice", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "order" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "post" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "rawPost" } ], "outputMappings": { "order": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_257aef29795246ec", "output": "order" } ] }, "post": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_257aef29795246ec", "output": "post" } ] }, "rawPost": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_257aef29795246ec", "output": "rawPost" } ] } } } }, "edges": [ { "source": "n_7e3e6783638f5afe", "target": "n_44a49850f9437a9d" }, { "source": "n_44a49850f9437a9d", "target": "n_998a598ebbfe3a17" }, { "source": "n_998a598ebbfe3a17", "target": "n_257aef29795246ec" }, { "source": "n_257aef29795246ec", "target": "n_7750a141afbdac3d" } ] } }, "modules": { "n_2a339c9420a23c05": { "name": "Build the purchase notice", "imports": [], "source": "export default function wooCommerceOrderNotice(input) {\n const order = input.order;\n if (!order || typeof order !== 'object' || Array.isArray(order) || !order.billing || typeof order.billing !== 'object' || typeof order.billing.first_name !== 'string' || !Array.isArray(order.line_items) || !order.line_items[0] || typeof order.line_items[0].name !== 'string') throw new Error('The order needs billing.first_name and the first line item name before notifying Mattermost');\n if (typeof input.channelId !== 'string' || !/^[a-z0-9]{26}$/.test(input.channelId)) throw new Error('Set the 26-character Mattermost channel ID');\n return { order, channelId: input.channelId, message: order.billing.first_name + ' bought ' + order.line_items[0].name + '!' };\n}\n" }, "n_64e956ce59302dbc": { "name": "Confirm the purchase notice", "imports": [], "source": "export default function wooCommerceMattermostReceipt(input) {\n const post = input.post;\n if (!post || typeof post !== 'object' || Array.isArray(post) || typeof post.id !== 'string' || !/^[a-z0-9]{26}$/.test(post.id) || post.channel_id !== input.channelId || post.message !== input.message) throw new Error('Mattermost did not confirm the expected post. It may already have accepted it; inspect the channel before replaying.');\n return { order: input.order, post, rawPost: input.rawPost };\n}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }