Best answer

Extract pattern using Formatter by Zapier


Badge

Hey everyone! 👋

I’m trying to extract an invoice number that’s coming from a Slack message (via Push to Zapier).

The Slack message has quite a bit of information, however, the invoice will always begin with ‘INV-’

My understanding is that I can use “Extract Pattern” in Formatting by Zapier to do this, but I’m not quite sure what to put in the pattern field (very new to Python!).

I’d love some help on how to essentially search the text of the message, look for the string starting with ‘INV-’ and return the whole string

Thanks in advance!

icon

Best answer by jayeshkumarbhatia 20 April 2023, 04:21

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.

10 replies

Userlevel 6
Badge +6

Hey @earlywork_team ,

 

Will the messages format be same everything on Slack? Can you share screenshot?

Badge

Hey @earlywork_team ,

 

Will the messages format be same everything on Slack? Can you share screenshot?

Hey @jayeshkumarbhatia 👋

Yep all the messages will be in the same format - it’s all triggered by another Zap actually. Here’s an example with dummy information

 

An invoice has been created for [name]! 

Email: [email]

Next steps:

1. Please log into Xero and approve the invoice - INV-0018

2. Click on the 3 dots on this message and click on "Push to Zapier"

✅ emoji when done

I’m looking to extract the INV-0018 specifically

Userlevel 6
Badge +6

Hey @earlywork_team 

 

I can give you an alternate solution. You can use Code by Zapier for this.

 

For example purpose, lets assume you get below message on webhook

 

 

Below is the screenshot of Code by Zapier where we extract invoice number 

 

 

On testing, we get below value

 

 

Below is the Javascript code which you can copy and pase in your Zapier account

var message = inputData.message
var invoiceNumber = message.split("invoice - ")[1].split("2. Click")[0]

output = {invoiceNumber }

 

Badge

Hey @earlywork_team 

 

I can give you an alternate solution. You can use Code by Zapier for this.

 

For example purpose, lets assume you get below message on webhook

 

 

Below is the screenshot of Code by Zapier where we extract invoice number 

 

 

On testing, we get below value

 

 

Below is the Javascript code which you can copy and pase in your Zapier account

var message = inputData.message
var invoiceNumber = message.split("invoice - ")[1].split("2. Click")[0]

output = {invoiceNumber }

 

Wow thank you so much for this @jayeshkumarbhatia! I’ve just implemented the JS code and I can see that the output is producing the right thing! 

 

I’m now running into the issue where I can’t actually use this data in following steps - now that I have the invoice number extracted, I want to use Xero to find that invoice so it can be sent out. Right now the full steps are

  1. Send data from Slack message using Push to Zapier 
  2. Extract the invoice number using the method above using JS
  3. Find invoice in Xero

The problem is that when I test the “Push to Zapier” step, it doesn’t use real data and so this is what I get in later steps. Any ideas on how I can get around this? 

 

Userlevel 6
Badge +6

Can you share the test data from Slack trigger event New Pushed Message

Badge

Can you share the test data from Slack trigger event New Pushed Message

Yep here you go!

message

channel__id: C3P718HHQ

channel__name: general

permalink: sfmqk://zogorp.nviss.doh/orbjamer/S5FMLBQ89/k9649888993000005

raw_text: [TEST/USER] hi

team__domain: zapier-testing

team__email_domain: zapier.com

team__icon__large_image_url: https://s3-us-west-2.amazonaws.com/slack-files2/avatars/2017-02-10/139442386353_55b863a5e4781fa06f14_230.png

team__icon__medium_image_url: https://s3-us-west-2.amazonaws.com/slack-files2/avatars/2017-02-10/139442386353_55b863a5e4781fa06f14_88.png

team__icon__small_image_url: https://s3-us-west-2.amazonaws.com/slack-files2/avatars/2017-02-10/139442386353_55b863a5e4781fa06f14_34.png

team__id: T3P9LPRAR

team__name: Zapier Testing Zone

text: [TEST/USER] hi

thread_ts: 1503349734.000163

ts: 1503349734.000163

ts_time: 2023-01-05T21:15:51Z

user__id: U3PTBLY31

user__is_bot: false

user__is_restricted: false

user__is_ultra_restricted: false

user__name: xavdid

user__profile__email: david@zapier.com

user__profile__first_name: David

user__profile__large_image_url: https://avatars.slack-edge.com/2017-03-07/150703672532_e566dfc673833e885a53_192.jpg

user__profile__last_name: test-1503349735

user__profile__medium_image_url: https://avatars.slack-edge.com/2017-03-07/150703672532_e566dfc673833e885a53_72.jpg

user__profile__phone: 123.555.1206

user__profile__small_image_url: https://avatars.slack-edge.com/2017-03-07/150703672532_e566dfc673833e885a53_24.jpg

user__real_name: David test-1503349735

text_added: This is the text that you entered into the textbox!

When I try to load more messages it says it can’t find any. From other threads I looked through, it seems like Push by Zapier can only use dummy data and it won’t use real data

Do you reckon this will be a problem for this method of implementation?

Userlevel 6
Badge +6

Hey @earlywork_team ,

 

The reason Code by Zapier is not working because the message is blank in the test data.

Badge

Hey @earlywork_team ,

 

The reason Code by Zapier is not working because the message is blank in the test data.

 

Hey @jayeshkumarbhatia! I tried to load the proper message to test out with the Push by Zapier step but I keep getting this error even though i’ve sent a lot of messages through

The only message it loads seems to be this one with dummy data

As such the following steps don’t allow me to properly use the outputs from the JS snippet :/ 

 

Userlevel 6
Badge +6

Ok, Something is not configured properly and due to this test data is not visible. To test the code i have written we require message in the test data. 

Badge

Ok, Something is not configured properly and due to this test data is not visible. To test the code i have written we require message in the test data. 

 

Yeah looks like it! I just found this thread where the author ran into a similar issue - 

 I’ll try go through some of the workarounds suggested here. Thank you so much for your help so far!