{
  "name": "Blip ticket emails",
  "nodes": [
    {
      "parameters": {
        "content": "## Blip ticket emails\nBlip posts one event here at each moment in a support ticket's life. This workflow sends the email, from your own address. Blip sends your visitors nothing itself.\n\n**1.** In each **Email** node, pick your own mail account (an SMTP credential), set **From Email** to your own address, and change the words to yours. n8n won't publish until each one has an account.\n**2.** Delete the branch of any moment you don't want to email.\n**3.** Press **Publish**. Then open **Blip ticket event**, copy its **Production URL**, and paste it in Blip: Settings, Email.\n**4.** Press **Send a test** in Blip. A test stops at **Which moment** (it's about a made-up visitor), so nothing is emailed for it. File a ticket from your own site to see a real one.\n\nSend one email per `event_key`: Blip tries an event again if this workflow doesn't answer.\n\n### Replies by email (optional)\nSomeone who presses Reply writes to your mailbox, not their ticket. To bring those replies onto the ticket:\n**5.** Add a last line to each email: `Ref: {{ $json.body.reply_token }}`. Mail programs quote it back under the reply.\n**6.** Turn on **Reply arrives** and **Post the reply to Blip** (they're switched off), and give **Reply arrives** your mailbox's IMAP account.\n**7.** Press **Publish** again. Blip keeps what they wrote and drops the email it quotes. Leave both off and nothing changes: the ticket page link in your email always works.",
        "height": 600,
        "width": 420
      },
      "id": "b11b0000-0000-4000-8000-000000000001",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        -200
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "blip-ticket-emails",
        "options": {}
      },
      "id": "b11b0000-0000-4000-8000-000000000002",
      "name": "Blip ticket event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "b11b0000-0000-4000-8000-000000000009"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b11b0000-0000-4000-8000-000000000100",
                    "leftValue": "={{ String($json.body.test ?? false) }}",
                    "rightValue": "true",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "A test from Blip"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b11b0000-0000-4000-8000-000000000101",
                    "leftValue": "={{ $json.body.type }}",
                    "rightValue": "ticket.created",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Filed"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b11b0000-0000-4000-8000-000000000102",
                    "leftValue": "={{ $json.body.type }}",
                    "rightValue": "ticket.replied",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  },
                  {
                    "id": "b11b0000-0000-4000-8000-000000000103",
                    "leftValue": "={{ $json.body.message?.from ?? '' }}",
                    "rightValue": "team",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Answered"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b11b0000-0000-4000-8000-000000000104",
                    "leftValue": "={{ $json.body.type }}",
                    "rightValue": "ticket.status_changed",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  },
                  {
                    "id": "b11b0000-0000-4000-8000-000000000105",
                    "leftValue": "={{ $json.body.ticket?.status ?? '' }}",
                    "rightValue": "done",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Marked done"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "b11b0000-0000-4000-8000-000000000106",
                    "leftValue": "={{ $json.body.type }}",
                    "rightValue": "ticket.solved_check",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Did that fix it?"
            }
          ]
        },
        "options": {}
      },
      "id": "b11b0000-0000-4000-8000-000000000003",
      "name": "Which moment",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "fromEmail": "you@example.com",
        "toEmail": "={{ $json.body.visitor.email }}",
        "subject": "=We've got your report, ticket {{ $json.body.ticket.ref }}",
        "emailFormat": "text",
        "text": "=Hi {{ $json.body.visitor.first_name }},\n\nThanks for telling us. Your report is with our team as ticket {{ $json.body.ticket.ref }}.\n\nYou can follow it, or add to it, here: {{ $json.body.status_url }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "b11b0000-0000-4000-8000-000000000004",
      "name": "Email: we've got your report",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        520,
        -300
      ]
    },
    {
      "parameters": {
        "fromEmail": "you@example.com",
        "toEmail": "={{ $json.body.visitor.email }}",
        "subject": "=Our answer to your report, ticket {{ $json.body.ticket.ref }}",
        "emailFormat": "text",
        "text": "=Hi {{ $json.body.visitor.first_name }},\n\n{{ $json.body.message.body }}\n\nRead the whole thread or write back here: {{ $json.body.status_url }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "b11b0000-0000-4000-8000-000000000005",
      "name": "Email: our answer",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        520,
        -100
      ]
    },
    {
      "parameters": {
        "fromEmail": "you@example.com",
        "toEmail": "={{ $json.body.visitor.email }}",
        "subject": "=Your report is sorted, ticket {{ $json.body.ticket.ref }}",
        "emailFormat": "text",
        "text": "=Hi {{ $json.body.visitor.first_name }},\n\nWe've marked your report “{{ $json.body.ticket.title }}” as sorted.\n\nIf it comes back, write to us here and it reopens: {{ $json.body.status_url }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "b11b0000-0000-4000-8000-000000000006",
      "name": "Email: your report is sorted",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        520,
        100
      ]
    },
    {
      "parameters": {
        "fromEmail": "you@example.com",
        "toEmail": "={{ $json.body.visitor.email }}",
        "subject": "=Did that fix it? Ticket {{ $json.body.ticket.ref }}",
        "emailFormat": "text",
        "text": "=Hi {{ $json.body.visitor.first_name }},\n\nA few days ago we answered your report “{{ $json.body.ticket.title }}”. Did that fix it?\n\nYes, it's fixed: {{ $json.body.solved_url }}\nNo, not yet: {{ $json.body.not_solved_url }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "b11b0000-0000-4000-8000-000000000007",
      "name": "Email: did that fix it?",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        520,
        300
      ]
    },
    {
      "parameters": {
        "mailbox": "INBOX",
        "postProcessAction": "read",
        "format": "simple",
        "options": {}
      },
      "id": "b11b0000-0000-4000-8000-000000000008",
      "name": "Reply arrives",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [
        0,
        560
      ],
      "disabled": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://sendablip.com/api/support/tickets/reply",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "keypair",
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $json.textPlain }}"
            },
            {
              "name": "html",
              "value": "={{ $json.textHtml }}"
            },
            {
              "name": "to",
              "value": "={{ $json.to }}"
            },
            {
              "name": "subject",
              "value": "={{ $json.subject }}"
            },
            {
              "name": "message_id",
              "value": "={{ $json.metadata['message-id'] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "b11b0000-0000-4000-8000-000000000009",
      "name": "Post the reply to Blip",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        560
      ],
      "disabled": true
    }
  ],
  "connections": {
    "Blip ticket event": {
      "main": [
        [
          {
            "node": "Which moment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Which moment": {
      "main": [
        [],
        [
          {
            "node": "Email: we've got your report",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email: our answer",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email: your report is sorted",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email: did that fix it?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply arrives": {
      "main": [
        [
          {
            "node": "Post the reply to Blip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
