Best answer

Slack Message to different Google Sheets columns

  • 17 December 2020
  • 2 replies
  • 86 views

Userlevel 1

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 :)

icon

Best answer by mateus 18 December 2020, 00:13

View original

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

Userlevel 7
Badge +14

Need clarification:

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

What 3 lines?

Userlevel 1

 

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!