Best answer

Payload multiple text extraction required

  • 2 July 2020
  • 6 replies
  • 1215 views

Userlevel 1

Hi, From the following SMS payload, I am struggling to extract 3 information

  • message__account_recipients id (only the phone number):
  • message__preview
  • conversation__web_url

Using Text to Formatter I can retrieve one of the three but when trying to add a second Text to Formatter Do this action it returns nothing/empty even though when use alone the second/third extract pattern return the expected value. 

Here 2 extract pattern use: 

  • (?<=account_recipients\"\:\[\{"id":")[\+[0-9]{12}
  • (?<=preview":").*(?=","type")

I guess I am not using the right extraction strategy by trying to cascade Text to Formatter actions.

Would someone be humble enough to help a rookie? 

 

{"rule":{"id":"9e873aa0-52aa-490f-869c-5335a8aa24f","description":"Oubound SMS","type":"outgoing_twilio_message"},"conversation":{"id":"9d11294-472d-480d-a410-370d6aab32f","subject":null,"latest_message_subject":"SMS with +1 (418) 885-0600","organization":{"id":"f152a8a0-f8cd-43d1-8a40-58a57c490b","name":"SDQ"},"color":null,"assignees":[{"id":"d70217-242a-414f-a847-88a326c5e64","name":"Shimoda ","email":"shimoda@gmail.com","unassigned":false,"closed":true,"archived":true,"trashed":false,"junked":false,"assigned":false,"flagged":false,"snoozed":false}],"users":[{"id":"d70da7-242a-414f-a847-88a5326c5e64","name":"Shimoda ","email":"shimoda@gmail.com","unassigned":false,"closed":true,"archived":true,"trashed":false,"junked":false,"assigned":false,"flagged":false,"snoozed":false}],"attachments_count":5,"messages_count":48,"authors":[{"name":"+1 (581) 204-0105","address":null},{"name":"+1 (418) 885-0600","address":null}],"drafts_count":0,"send_later_messages_count":0,"tasks_count":0,"completed_tasks_count":0,"web_url":"https://mail.missiveapp.com/#inbox/conversations/9d1e4-472d-480d-a410-370d68aab32f","app_url":"missive://mail.missiveapp.com/#inbox/conversations/9d11e4-472d-480d-a410-370d68aab32f","assignee_names":"Shimoda ","assignee_emails":"shimoda@gmail.com","shared_label_names":"","shared_labels":[]},"message":{"id":"207a8f-dc28-4111-af95-34a33eec03b","subject":"","preview":"8888","type":"twilio","delivered_at":1593858271,"updated_at":1593698271,"created_at":1593688260,"account_author":{"id":"AC5dad458cc92927226f4d60f8abc28","name":"+1 (581) 204-0105","username":"+15812040102"},"account_recipients":[{"id":"+14188850600","name":"+1 (418) 885-0600","username":null}],"author":{"id":"d70da2-242a-414f-a847-88a5326c5e64","email":"shimoda@gmail.com","name":"Shimoda ","avatar_url":"https://missive-attachments.s3.us-east-1.amazonaws.com/239bae60-b465-468c-9a43-5ed424e5e0a2/AOh14GiAmwxi_LXovdPjwHFJbhda7qoQzmciIJecdKg"}}}

 

icon

Best answer by ikbelkirasan 2 July 2020, 21:04

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.

6 replies

Userlevel 7
Badge +12

@Shimoda - Try parsing that payload in a Code by Zapier (JavaScript) step. Make sure to pass the payload in an input field called payload.

const { payload } = inputData;
const data = JSON.parse(payload);

output = [data];

 

Userlevel 1

Thanks @ikbelkirasan for this input! 

I have got lost trying to follow you on the next picture. I which I could understand but I was missing certain pieces of you solution. 

 

At least you inspired me to find this solution. Thanks to you! 

Where here above I can extract the phone number. All other needed values are provided by the Catch Hook.

Userlevel 7
Badge +12

@Shimoda - You’re welcome and thanks for the additional info!

Could you turn the webhook trigger into a Catch Raw Hook? This will allow you to pass the whole payload to the code step as I mentioned before. Check out the screenshots below:

 

 

 

The whole JSON payload is available in the raw_body field which we can use in the subsequent Code step.

 

 

 

Here’s the code:

const { payload } = inputData;
const data = JSON.parse(payload);

const recipientIds = {};
data["message"]["account_recipients"].forEach(
(recipient, i) => {
recipientIds[`recipient_${i + 1}`] = recipient["id"];
}
);

const message = data["message"]["preview"]
const missiveWebURL = data["conversation"]["web_url"]
const missiveAppURL = data["conversation"]["app_url"]

output = [{
recipientIds,
message,
missiveWebURL,
missiveAppURL
}];

 

I hope this helps!

Userlevel 1

Very nice @ikbelkirasan ! Thank you for sharing your elegant solution!

Userlevel 7
Badge +12

@Shimoda - Great! Did this solve your problem?

Userlevel 1

It would have! I went ahead with the solution I found following your first reply. 

Thanks again@ikbelkirasan !