Skip to main content
Best answer

Slack Message to different Google Sheets columns

  • December 17, 2020
  • 2 replies
  • 98 views

Hello everyone,

 

Our slack messages come in 5 lines like this:

Topic: xxx
Name: xxx
E-Mail: @
Order Number: 1111
Comment: bla

Is there anyway to get all 3 lines into 3 separate Google Sheet columns for better organization?
So far I have only found this solution here, which requires coding :)

Best answer by mateus

 

Assuming your message lines maintain the exact same pattern (e.g.: Subject: Description), you can use Javascript to dissect your message and return them as a list.

  1. Pass your new Slack message as the message property in your inputData object.
  2. Add the following code:
const { message } = inputData; // This is your message.
const keys = message.match(/^.+(?=:)/gm); // Matches the left side of the colon in each line. This is why it's important to keep the same message structure.
const messageDetails = {}; // Your dissected message will reside here.

keys.forEach(key => {
const valueRegexp = new RegExp(`(?<=^${key}: ).+`, 'gm');
const value = message.match(valueRegexp);
messageDetails[key] = value;
});

return messageDetails;

 

Tried and true:

 

If you ever need to add more lines of text, this should work without any further changes, as long as you keep the same message structure.

Now you should be able to attribute these pieces of data to any Google Sheets column you want!

Hope it helps!

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • December 17, 2020

Need clarification:

Is there anyway to get all 3 lines into 3 separate Google Sheet columns for better organization?

What 3 lines?


mateus
  • New
  • Answer
  • December 17, 2020

 

Assuming your message lines maintain the exact same pattern (e.g.: Subject: Description), you can use Javascript to dissect your message and return them as a list.

  1. Pass your new Slack message as the message property in your inputData object.
  2. Add the following code:
const { message } = inputData; // This is your message.
const keys = message.match(/^.+(?=:)/gm); // Matches the left side of the colon in each line. This is why it's important to keep the same message structure.
const messageDetails = {}; // Your dissected message will reside here.

keys.forEach(key => {
const valueRegexp = new RegExp(`(?<=^${key}: ).+`, 'gm');
const value = message.match(valueRegexp);
messageDetails[key] = value;
});

return messageDetails;

 

Tried and true:

 

If you ever need to add more lines of text, this should work without any further changes, as long as you keep the same message structure.

Now you should be able to attribute these pieces of data to any Google Sheets column you want!

Hope it helps!