Hi community. Newbie question: I have a slash com...
# general
c
Hi community. Newbie question: I have a slash command from slack that passes in the argument like this, because Slack autodetects that it’s an email address. I have the email address in a transform and am trying to figure out the best way to parse out the email address into a Tines variable. I went through all the functions and nothing seemed quite like what I wanted. Ideas?
"text":"<mailto:<mailto:brent@bluecore.com|brent@bluecore.com>|<mailto:brent@bluecore.com|brent@bluecore.com>>",
g
Hey Brent! One way to handle this is to use regex to extract out the email address. You can copy paste this action in to your Story to take a look:
Copy code
{
  "agents": [
    {
      "disabled": false,
      "name": "Extract Email Addresses Using Regex",
      "options": "{\"mode\":\"extract\",\"matchers\":[{\"path\":\"{{receive_from_slack.body.text}}\",\"regexp\":\"\\\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4}\\\\b\",\"to\":\"emails\"}]}",
      "position": {
        "x": -405,
        "y": -1680
      },
      "type": "eventTransformation"
    }
  ],
  "links": [],
  "diagramNotes": []
}
Only thing to watch out for there is that this action will find 2 matches, so later on when you want to use the address, just specify the
first
one and you should be good to go. That will be something like:
extract_email_addresses_using_regex.emails.first
a
One other option is to use the
split
Liquid filter on
|
, cast it
as_object
, then in a subsequent action call the array of the split string
.last | remove: ">"
Copy code
{
  "agents": [
    {
      "disabled": false,
      "name": "Var",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"text\":\"<mailto:brent@bluecore.com|brent@bluecore.com>\"}}",
      "position": {
        "x": 555,
        "y": 315
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "Split",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"{{var.text | split: \\\"|\\\" | as_object}}\"}}",
      "position": {
        "x": 555,
        "y": 420
      },
      "type": "eventTransformation"
    },
    {
      "disabled": false,
      "name": "Isolate Email Address",
      "options": "{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"{{split.message.last | remove: \\\">\\\"}}\"}}",
      "position": {
        "x": 555,
        "y": 525
      },
      "type": "eventTransformation"
    }
  ],
  "links": [
    {
      "sourceIdentifier": 0,
      "receiverIdentifier": 1
    },
    {
      "sourceIdentifier": 1,
      "receiverIdentifier": 2
    }
  ],
  "diagramNotes": []
}
c
Got it working! Thanks all! You’re the best!
a
Hi all just want to thank you all. I used @great-beach-70934’s regex code to parse out email addresses in an IMAP action!
g
great! Glad it helped!