Hi team
I receive the body of a wqeb request, in particular from Chatwoot and then i get the content of the message, which is pretty straightforward adn i do not have issues with this.
The content part of the reply is only text. It may be though that someone who sent a message didn't add the attachments as attachments, but put them from a direct copy paste.
The content then is received as text with the attachment urls as well.
Content variable {[content}} made out of {{webResponse.body.messages.content}}
Logs:
ext text text  
so the real text here is ext text text
i make a variable {{contentInlineImages}} which stores the matched image urls from the content: {{content.match("!\\[\\]\\(([^\\)]+)\\)").split(",")}} and this logs
[https://app.chatwoot.com/rails/active_storage/blobs/redirect/......./image.png], [https://app.chatwoot.com/rails/active_storage/blobs/redirect/......./image.png]
Now i want to send an email and use each value of those urls so i can create a link:
{{#contentInlineImages}}
<a href="{{contentInlineImages}}">Attachment</a>
{{/contentInlineImages}}
it doesn't send anything.
If i remove the .split(".") and use the same template for the email it sends only one
What do i miss so i can make it iterate and send all links?
Best Regards
Hi @Bill Sheboy
Thanks for your suggestion
In fact i always print in the logs everything when i setup an autoamtion to be able to see what is happening in each step.
I still cannot figure out what is ahppening and how shoudl this be fixed...
I think this is not the case of the regex
This is what is happening:
Receiving a content like this:
Content: May 24, 1:46 A May 24, 2:21 AM May 24, 2:44 AM May 24, 3:25 AM May 24, 12:36 PM May 24, 1:15 PM 4. Jun 1, 11:46 PM Jun 1, 11:59 PM Jun 2, 12:44 AM Jun 2, 3:39 PM **LA** *   May 24, 1:46 A May 24, 2:21 AM *
This is logged in the automation from this:
Content:{{webResponse.body.messages.content}}
Then i create a variable {{contentInlineImages}} with the below:
{{content.match("!\\[\\]\\(([^\\)]+)\\)").split(",")}}
and this prints in the logs :
InlineImages:[https://app.chatwoot.com/rails/active_storage/blobs/redirect/....../image.png], [https://app.chatwoot.com/rails/active_storage/blobs/redirect/....../image.png]
So a comma separated list
Then i create an email automation step and i include as body:
Inline attachments
{{#contentInlineImages}}
<a href="{{.}}">Link</a><br>
{{/}}
I receive this in the email:
Inline attachments
Link
which is jsut the textand not a link, and as we see only one
if i use in the email body simply the iteration of the {{.}} without <a> tags
Inline attachments
{{#contentInlineImages}}
{{.}}<br>
{{/}}
i receive this in the email:
Inline attachments
[https://app.chatwoot.com/rails/active_storage/blobs/redirect/......./image.png],
[https://app.chatwoot.com/rails/active_storage/blobs/redirect/......./image.png]
another approach i took is intsead of using the {{contentInlineImages}} variable to directly use the construction of it in the email body:
Inline attachments
{{#content.match("!\\[\\]\\(([^\\)]+)\\)").split(",")}}
<a href="{{.}}">{{.}}</a><br>
{{/}}
I added the {{.}} as the name for the Links to see if it gets the urls, and as of my surprise it gets the urls with the [ ] , but doesn't make a link and prints this:
Inline attachments
[https://app.chatwoot.com/rails/active_storage/blobs/redirect/....../image.png]
[https://app.chatwoot.com/rails/active_storage/blobs/redirect/....../image.png]
So it gets the urls with [ ] as we see and prints them from the name part of the link, but doesn't make a link, it is just text printed there of course from the name part of the a tags but it is not a clickabel link
Thanks and regards
Please try to stay with one thread when responding. That will help others reading this question in the future know if there are multiple solution approaches. Thanks!
When you created the variable, that is stored as text. It is no longer a list.
Please try this to parse your saved variable by converting it back into a list:
{{#contentInlineImages.split(", ").match("[(.*)]")}}
<a href="{{.}}">Link</a>
{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
Yeah my bad with the reply out of the thread
I tried your iteration but it prints nothing, it is empty
And in the logs this:
ContentImages:{{contentInlineImages.split(", ").match("[(.*)]")}}
or
ContentImages:{{#contentInlineImages.split(", ").match("[(.*)]")}} <a href="{{.}}">Link</a> {{/}} do not print anything
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
Just managed to make it work:
The {{contentInlineImages}} variable instead of using split() i used join()
{{contentInlineImages}}
{{content.match("!\\[\\]\\(([^\\)]+)\\)").join(",")}}
This makes it a string of urls comma separated
Then in the email body construction i used split() on the variable
{{#contentInlineImages.split(",")}}
<a href="{{.}}">Image Link</a><br/>
{{/}}
And this creates links for each image
Thanks for your advice as always
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well done!
One of the challenges with splitting some text is ensuring the joining delimiter is a known string of text. The default appears to be comma-followed-by-a-space: ", ". That seems consistently used for lists but not arrays. What you did by explicitly adding the join(",") helps to confirm what to split() on later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For unique scenarios like this, I suggest doing this step by step, writing results to the audit log for each step, to observe when it stops working. That may confirm what the expression / variable contains that prevents split() from working as expected.
Also please note...
In my experience, the match() function in rules may not always handle complicated regular expressions well. This seems to be caused by which constructs are supported (or not) and the parsing order of the regular expression, particularly when it contains escaped characters.
Incrementally building up your regular expression, from the simplest first and adding edge cases later, may uncover the problem.
A technique to help with the apparent parsing order symptoms is to first store the regular expression in a variable, and then use that in the match. For example:
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.