{
    "name": "Connectly to Intercom",
    "flow": [
        {
            "id": 1,
            "module": "gateway:CustomWebHook",
            "version": 1,
            "parameters": {
                "hook": 28168,
                "maxResults": 1
            },
            "mapper": {},
            "metadata": {
                "designer": {
                    "x": -391,
                    "y": 0
                },
                "restore": {
                    "parameters": {
                        "hook": {
                            "data": {
                                "editable": "true"
                            },
                            "label": "Connectly-intercom-webhook"
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "hook",
                        "type": "hook:gateway-webhook",
                        "label": "Webhook",
                        "required": true
                    },
                    {
                        "name": "maxResults",
                        "type": "number",
                        "label": "Maximum number of results"
                    }
                ],
                "interface": [
                    {
                        "name": "topic",
                        "type": "text"
                    },
                    {
                        "name": "timestamp",
                        "type": "text"
                    },
                    {
                        "name": "sender",
                        "spec": [
                            {
                                "name": "id",
                                "type": "text"
                            },
                            {
                                "name": "channelType",
                                "type": "text"
                            },
                            {
                                "name": "name",
                                "type": "text"
                            }
                        ],
                        "type": "collection"
                    },
                    {
                        "name": "recipient",
                        "spec": [
                            {
                                "name": "id",
                                "type": "text"
                            },
                            {
                                "name": "channelType",
                                "type": "text"
                            },
                            {
                                "name": "name",
                                "type": "text"
                            }
                        ],
                        "type": "collection"
                    },
                    {
                        "name": "buttonResponse",
                        "spec": [
                            {
                                "name": "id",
                                "type": "text"
                            },
                            {
                                "name": "text",
                                "type": "text"
                            },
                            {
                                "name": "payload",
                                "type": "text"
                            }
                        ],
                        "type": "collection"
                    }
                ]
            }
        },
        {
            "id": 2,
            "module": "intercom:createUserOrLead",
            "version": 1,
            "parameters": {
                "__IMTCONN__": 42588
            },
            "mapper": {
                "name": "{{1.sender.name}}",
                "type": "user",
                "email": "{{replace(1.sender.id; \"+\"; )}}@connectly.ai",
                "phone": "{{1.sender.id}}",
                "user_id": "",
                "companies": [],
                "signed_up_at": "",
                "custom_attributes": {
                    "Num_orders": "",
                    "CPF ou CNPJ": "",
                    "Friday - ok": "",
                    "Link_survey": "",
                    "Monday - ok": "",
                    "Sunday - ok": "",
                    "Tuesday - ok": "",
                    "Saturday - ok": "",
                    "Thursday - ok": "",
                    "Friday - block": "",
                    "Monday - block": "",
                    "Sunday - block": "",
                    "Wednesday - ok": "",
                    "Tuesday - Block": "",
                    "Saturday - block": "",
                    "Thursday - block": "",
                    "Wednesday - block": ""
                }
            },
            "metadata": {
                "designer": {
                    "x": 300,
                    "y": 0
                },
                "restore": {
                    "expect": {
                        "type": {
                            "label": "User"
                        },
                        "companies": {
                            "mode": "chose"
                        },
                        "unsubscribed_from_emails": {
                            "mode": "chose"
                        }
                    },
                    "parameters": {
                        "__IMTCONN__": {
                            "data": {
                                "scoped": "true",
                                "connection": "intercom"
                            },
                            "label": "Intercom connection ()"
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "__IMTCONN__",
                        "type": "account:intercom",
                        "label": "Connection",
                        "required": true
                    }
                ],
                "expect": [
                    {
                        "name": "type",
                        "type": "select",
                        "label": "Type",
                        "required": true,
                        "validate": {
                            "enum": [
                                "user",
                                "lead"
                            ]
                        }
                    },
                    {
                        "name": "custom_attributes",
                        "spec": [
                            {
                                "name": "Num_orders",
                                "type": "integer"
                            },
                            {
                                "name": "Link_survey",
                                "type": "text"
                            },
                            {
                                "name": "CPF ou CNPJ",
                                "type": "text"
                            },
                            {
                                "name": "Monday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Tuesday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Wednesday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Thursday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Friday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Saturday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Sunday - ok",
                                "type": "text"
                            },
                            {
                                "name": "Monday - block",
                                "type": "text"
                            },
                            {
                                "name": "Tuesday - Block",
                                "type": "text"
                            },
                            {
                                "name": "Wednesday - block",
                                "type": "text"
                            },
                            {
                                "name": "Thursday - block",
                                "type": "text"
                            },
                            {
                                "name": "Friday - block",
                                "type": "text"
                            },
                            {
                                "name": "Saturday - block",
                                "type": "text"
                            },
                            {
                                "name": "Sunday - block",
                                "type": "text"
                            }
                        ],
                        "type": "collection",
                        "label": "Custom Fields"
                    },
                    {
                        "name": "email",
                        "type": "email",
                        "label": "Email address"
                    },
                    {
                        "name": "user_id",
                        "type": "text",
                        "label": "User ID"
                    },
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Name"
                    },
                    {
                        "name": "phone",
                        "type": "text",
                        "label": "Phone number"
                    },
                    {
                        "name": "signed_up_at",
                        "time": true,
                        "type": "date",
                        "label": "Signed up at"
                    },
                    {
                        "name": "unsubscribed_from_emails",
                        "type": "boolean",
                        "label": "Unsubscribed from emails"
                    },
                    {
                        "name": "companies",
                        "spec": [
                            {
                                "name": "company_id",
                                "type": "select",
                                "label": "Company ID",
                                "required": true
                            },
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Name"
                            },
                            {
                                "name": "monthly_spend",
                                "type": "number",
                                "label": "Monthly spend"
                            }
                        ],
                        "type": "array",
                        "label": "Companies"
                    }
                ]
            }
        },
        {
            "id": 3,
            "module": "intercom:makeApiCall",
            "version": 1,
            "parameters": {
                "__IMTCONN__": 42588
            },
            "mapper": {
                "qs": [],
                "url": "/conversations/search",
                "body": "{\n \"query\":  {\n    \"operator\": \"AND\",\n    \"value\": [\n      {\n        \"field\": \"source.author.email\",\n        \"operator\": \"=\",\n        \"value\":\"{{2.email}}\"\n      }, \n      {\n        \"field\": \"source.author.type\",\n        \"operator\": \"=\",\n        \"value\": \"user\"\n      },\n      {\n        \"field\": \"open\",\n        \"operator\": \"=\",\n        \"value\": true\n      }\n    ]\n  }\n}",
                "method": "POST",
                "headers": [
                    {
                        "key": "Content-Type",
                        "value": "application/json"
                    },
                    {
                        "key": "Intercom-Version",
                        "value": "2.4"
                    }
                ]
            },
            "metadata": {
                "designer": {
                    "x": 600,
                    "y": 0
                },
                "restore": {
                    "expect": {
                        "qs": {
                            "mode": "chose"
                        },
                        "method": {
                            "mode": "chose",
                            "label": "POST"
                        },
                        "headers": {
                            "mode": "chose",
                            "items": [
                                null,
                                null
                            ]
                        }
                    },
                    "parameters": {
                        "__IMTCONN__": {
                            "data": {
                                "scoped": "true",
                                "connection": "intercom"
                            },
                            "label": "Intercom connection ()"
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "__IMTCONN__",
                        "type": "account:intercom",
                        "label": "Connection",
                        "required": true
                    }
                ],
                "expect": [
                    {
                        "name": "url",
                        "type": "text",
                        "label": "URL",
                        "required": true
                    },
                    {
                        "name": "method",
                        "type": "select",
                        "label": "Method",
                        "required": true,
                        "validate": {
                            "enum": [
                                "GET",
                                "POST",
                                "PUT",
                                "PATCH",
                                "DELETE"
                            ]
                        }
                    },
                    {
                        "name": "headers",
                        "spec": [
                            {
                                "name": "key",
                                "type": "text",
                                "label": "Key"
                            },
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Value"
                            }
                        ],
                        "type": "array",
                        "label": "Headers"
                    },
                    {
                        "name": "qs",
                        "spec": [
                            {
                                "name": "key",
                                "type": "text",
                                "label": "Key"
                            },
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Value"
                            }
                        ],
                        "type": "array",
                        "label": "Query String"
                    },
                    {
                        "name": "body",
                        "type": "any",
                        "label": "Body"
                    }
                ]
            },
            "onerror": [
                {
                    "id": 4,
                    "module": "intercom:userOrLeadInitiatedConversation",
                    "version": 1,
                    "parameters": {
                        "__IMTCONN__": 42588
                    },
                    "mapper": {
                        "body": "{{ifempty(1.message.text; 1.buttonResponse.text)}}",
                        "from": {
                            "id": "{{2.id}}",
                            "type": "user"
                        }
                    },
                    "metadata": {
                        "designer": {
                            "x": 603,
                            "y": 456
                        },
                        "restore": {
                            "expect": {
                                "from": {
                                    "nested": {
                                        "id": {
                                            "mode": "edit"
                                        },
                                        "type": {
                                            "label": "User"
                                        }
                                    }
                                }
                            },
                            "parameters": {
                                "__IMTCONN__": {
                                    "data": {
                                        "scoped": "true",
                                        "connection": "intercom"
                                    },
                                    "label": "Intercom connection ()"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "__IMTCONN__",
                                "type": "account:intercom",
                                "label": "Connection",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "body",
                                "type": "text",
                                "label": "Message",
                                "required": true
                            },
                            {
                                "name": "from",
                                "spec": [
                                    {
                                        "name": "type",
                                        "type": "select",
                                        "label": "Type",
                                        "required": true,
                                        "validate": {
                                            "enum": [
                                                "user",
                                                "contact"
                                            ]
                                        }
                                    },
                                    {
                                        "mode": "edit",
                                        "name": "id",
                                        "type": "select",
                                        "label": "Intercom ID"
                                    }
                                ],
                                "type": "collection",
                                "label": "From"
                            }
                        ]
                    }
                }
            ]
        },
        {
            "id": 6,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "sorted_convos",
                "scope": "roundtrip",
                "value": "{{sort(3.body.conversations; \"desc\"; \"created_at\")}}"
            },
            "metadata": {
                "designer": {
                    "x": 948,
                    "y": -3
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One cycle"
                        }
                    }
                },
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    },
                    {
                        "name": "scope",
                        "type": "select",
                        "label": "Variable lifetime",
                        "required": true,
                        "validate": {
                            "enum": [
                                "roundtrip",
                                "execution"
                            ]
                        }
                    },
                    {
                        "name": "value",
                        "type": "any",
                        "label": "Variable value"
                    }
                ],
                "interface": [
                    {
                        "name": "sorted_convos",
                        "type": "any",
                        "label": "sorted_convos"
                    }
                ]
            }
        },
        {
            "id": 7,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "top_one_convo",
                "scope": "roundtrip",
                "value": "{{get(6.sorted_convos; 1)}}"
            },
            "metadata": {
                "designer": {
                    "x": 1282,
                    "y": -5
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One cycle"
                        }
                    }
                },
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    },
                    {
                        "name": "scope",
                        "type": "select",
                        "label": "Variable lifetime",
                        "required": true,
                        "validate": {
                            "enum": [
                                "roundtrip",
                                "execution"
                            ]
                        }
                    },
                    {
                        "name": "value",
                        "type": "any",
                        "label": "Variable value"
                    }
                ],
                "interface": [
                    {
                        "name": "top_one_convo",
                        "type": "any",
                        "label": "top_one_convo"
                    }
                ]
            }
        },
        {
            "id": 8,
            "module": "intercom:replyToConversation",
            "version": 1,
            "parameters": {
                "__IMTCONN__": 42588
            },
            "mapper": {
                "body": "{{ifempty(1.message.text; 1.buttonResponse.text)}}",
                "type": "user",
                "conv_id": "{{get(7.top_one_convo; \"id\")}}",
                "message_type": "comment",
                "attachment_urls": [],
                "intercom_user_id": "{{2.id}}"
            },
            "metadata": {
                "designer": {
                    "x": 1582,
                    "y": -5
                },
                "restore": {
                    "expect": {
                        "type": {
                            "label": "User"
                        },
                        "conv_id": {
                            "mode": "edit"
                        },
                        "intercom_user_id": {
                            "mode": "edit"
                        }
                    },
                    "parameters": {
                        "__IMTCONN__": {
                            "data": {
                                "scoped": "true",
                                "connection": "intercom"
                            },
                            "label": "Intercom connection ()"
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "__IMTCONN__",
                        "type": "account:intercom",
                        "label": "Connection",
                        "required": true
                    }
                ],
                "expect": [
                    {
                        "name": "conv_id",
                        "type": "select",
                        "label": "Conversation",
                        "required": true
                    },
                    {
                        "name": "type",
                        "type": "select",
                        "label": "Type",
                        "required": true,
                        "validate": {
                            "enum": [
                                "user",
                                "admin"
                            ]
                        }
                    },
                    {
                        "name": "message_type",
                        "type": "hidden"
                    },
                    {
                        "name": "body",
                        "type": "text",
                        "label": "Message",
                        "required": true
                    },
                    {
                        "mode": "edit",
                        "name": "intercom_user_id",
                        "type": "select",
                        "label": "ID",
                        "required": true
                    },
                    {
                        "name": "attachment_urls",
                        "spec": {
                            "name": "value",
                            "type": "url",
                            "label": "URL",
                            "required": true
                        },
                        "type": "array",
                        "label": "Attachment URLs",
                        "validate": {
                            "maxItems": 5
                        }
                    }
                ]
            },
            "onerror": [
                {
                    "id": 9,
                    "module": "intercom:userOrLeadInitiatedConversation",
                    "version": 1,
                    "parameters": {
                        "__IMTCONN__": 42588
                    },
                    "mapper": {
                        "body": "{{ifempty(1.message.text; 1.buttonResponse.text)}}",
                        "from": {
                            "id": "{{2.id}}",
                            "type": "user"
                        }
                    },
                    "metadata": {
                        "designer": {
                            "x": 1882,
                            "y": -5
                        },
                        "restore": {
                            "expect": {
                                "from": {
                                    "nested": {
                                        "id": {
                                            "mode": "edit"
                                        },
                                        "type": {
                                            "label": "User"
                                        }
                                    }
                                }
                            },
                            "parameters": {
                                "__IMTCONN__": {
                                    "data": {
                                        "scoped": "true",
                                        "connection": "intercom"
                                    },
                                    "label": "Intercom connection ()"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "__IMTCONN__",
                                "type": "account:intercom",
                                "label": "Connection",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "body",
                                "type": "text",
                                "label": "Message",
                                "required": true
                            },
                            {
                                "name": "from",
                                "spec": [
                                    {
                                        "name": "type",
                                        "type": "select",
                                        "label": "Type",
                                        "required": true,
                                        "validate": {
                                            "enum": [
                                                "user",
                                                "contact"
                                            ]
                                        }
                                    },
                                    {
                                        "mode": "edit",
                                        "name": "id",
                                        "type": "select",
                                        "label": "Intercom ID"
                                    }
                                ],
                                "type": "collection",
                                "label": "From"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "instant": true,
        "version": 1,
        "scenario": {
            "roundtrips": 1,
            "maxErrors": 3,
            "autoCommit": true,
            "autoCommitTriggerLast": true,
            "sequential": false,
            "confidential": false,
            "dataloss": false,
            "dlq": false
        },
        "designer": {
            "orphans": []
        },
        "zone": "us1.make.com"
    }
}