Capturing User Emails

Summary

Slack gives us a link to an email address when someone replies with an email, so we can use a little Javascript Macro magic to strip away the extra content.

Snippet

# punctopic nostrip
 
> object slackEmail javascript
  email = args[0].split(/[:|>]/)[1];
  rs.setUservar(rs.currentUser(), 'email', email);
  rs.reply(rs.currentUser(), 'confirm');
< object
 
+ get email
- What email address would you like us to send this email to?
 
+ *
* <get _platform> == slack => <call>slackEmail <star></call>
- <set email=<star>> {@ confirm}
 
+ confirm
- Okay your email is <get email>, is that correct?
 
+ yes
- Perfect, your email is set to <get email>.
 
+ no
- Okay, try again. Like this: youremail@email.com <set email>

Explanation

Slack returns mailto:myemail@email.com|myemail@email.com when a user replies with their email. We can use a Conditional to check if a bot user’s platform is Slack, and then use a simple Javascript Macro that splits the email, and sets a User Variable to capture your bot user’s email.

The script uses a basic confirmation flow to confirm that your bot user entered in their email correctly. This is best practice for user experience, and to make sure you have their correct email.