Question
My Zendesk Support account is heavily automated with triggers and automations and there is no simple way to get rid of canned messages. How can I make my business rules send out varying communication using liquid markup?
Answer
You can use liquid markup to enable your triggers, automations, and macros to randomly select a pre-built message from a set of messages and send it to the customer.
Liquid doesn't have the ability to generate random numbers, so this requires that you build some logic. The current logic of liquid markup is the following:
- Liquid code takes the ticket ID number, which is almost random per user.
- Liquid code divides it by three and based on the remainder, displays a different text.
- The modulo: 3 (the remainder after division by three) can return three possible results: 0, 1, 2. Each result is associated with text that is displayed.
Liquid code
The code below represents the logic needed. Copy and paste it in your business rules.
{% assign randomizer = ticket.id | modulo:3 %}
{% case randomizer %} {% when 0 %}
Your request ({{ticket.id}}) has been solved. To reopen this request, reply to this email.<br /><br>
{% when 1 %}
We glad to inform that this matter is resolved. However, if you have any outstanding questions feel free to reply to this notification.
{% else %}
#{{ticket.id}} is now considered to be resolved. You are welcome to reply to this email to reopen it and continue the conversation.
{% endcase %}
{{ticket.comments_formatted}}
Using the Liquid code in business rules
- Trigger
Create a trigger that sends a notification when a ticket is marked as solved. Paste the liquid code in the email body of the notification. Then modify the possible messages as you like.
To test the trigger, solve three consecutive tickets and check the outcome of the notifications. Find below the images of the three notifications with different text.
- Automation
The same approach can be used for an automation. Let's assume you need an automation that will follow-up with a customer with different communication text after three days of no response.
- Macro
If your agents prefer sending follow-ups manually, they can create a macro that uses Liquid code and returns different messages based on the ticket ID.
Enhancement
The code in this article uses modulo: 3 to calculate the remainder after division. The argument can be easily increased to 5 or 10. Division by 5 means 5 possible remainders after division can exist. Each outcome can be associated with a message. This creates a straight forward logic for increasing the number of outcomes and, as a result, creating the impression of truly random responses.
23 Comments
Thanks for sharing @Andrey.
Love this, but getting unwanted carriage returns at the beginning and end of messages when used in a Macro. Anyone have any idea what I may be missing?
Pretty sure I've sorted this out now - just removed all carriage returns and spaces in the Liquid Markup and it seems to work.
Great, Terry! I'm glad you were able to get it sorted out, and thanks for sharing the solution. :)
Hey, this is a great post! What I'm wondering is if I can use Liquid markup to change a custom field on the ticket, rather than show/hide text in the email notification.
In other words, I'd like to use the modulo: 3 logic to set a checkbox to TRUE for a randomized 1/3 of my tickets. Is this possible?
hi Sam,
By idea Liquid can't change anything. It's templating language which can only show some text or HTML.
If you want to randomly set ticket dropdown I would suggest to use triggers/automations for that. I haven't tried to to achieve something similar using business rules yet, so can't really point to right direction yet.
@Andrey Thanks! I'll work on that
Thanks for sharing this tip, Andrey.
I went even one step further and improved the randomizer, cause sometimes the "random" answer did not fit each ticket so much. The problem with the implementation above is that it's not random for each macro usage when you replace ticket id with the current time, it will be :)
The placeholder %L gives you the current milliseconds of the UNIX timestamp, e.g. 674.
Hello all!
We run an automation and for the signature of the user, we want to use a randomiser so that this automation appears like one of many different users instead of always replying with the same name. So, for the signature I have pasted a dynamic content template. The content itself looks like this:
{% assign randomizer_automation_name = ticket.id | modulo:9 %}{% case randomizer_automation_name %}{% when 0 %}**Name 1**{% when 1 %}**Name 2**{% when 2 %}**Name 3**{% when 3 %}**Name 4**{% when 4 %}**Name 5**{% when 5 %}**Name 6**{% when 6 %}**Name 7**{% when 7 %}**Name 8**{% when 8 %}**Name 9**{% when 9 %}**Name 10**{% else %}**Name 10**{% endcase %}
For some reason, it always returns "Name 1" when used. What can be the cause for this? Is the reason it returns 0 because the ticket ID is not checkable when using this in a Signature?
@Andreas,
thanks for sharing. Using date makes much more sense. At the time of writing this article I was not that pro in liquid. These days I would also consider the date/timestamp. Glad you've shared it!
@Christofer,
>Is the reason it returns 0 because the ticket ID is not checkable when using this in a Signature?
That is correct. Luckly enough earlier this year I wrote an app which allows injecting HTML, complex liquid etc into signatures. This is Labs app, so has limited support, but it received many positive feedbacks so far. Check this out:
https://www.zendesk.com/apps/support/zignatures
@Andrey
Do you maybe know a way to get 2 different random values in a macro?
I had a use case where i wanted to fully automate the greeting forms in my tickets.
The problem is that when i am accessing "now" a second time, the return value is still the same, probably due to the fact that it happens in the same milisecond. There's also now wait/sleep function in liquid to prevent that from happening 😕
@Andreas,
Let me make sure I understood your use case here:
You want to apply a macro once on ticket X => the outcome should display VALUE1
Then, say, 2 mins later, you want to apply the same macro again, but on ticket Y => the outcome should display VALUE2
Is this accurate description ^ ?
Hello all,
Quick question, hope someone can help out.
Instead of having a responses "randomized" I'd like to tell the system "if its our first reply use X", "if its our second reply use Y" etc.
I once had this working well, now I cannot find the proper placeholder for the number of agent replies etc.
Can someone help?
Hey Felix!
I'll check to see if any of our Community Moderators can help with this. Stand by!
Hello Felix,
I don't see a placeholder for this.
If there really isn't one, you could define a series of tags, e.g. reply1, reply2, reply3, and define triggers to set these tags based on the "Agent replies" condition. Then you can test these tags in liquid conditionals to define alternate replies.
(Alternatively, of course, you could just have different triggers sending different replies for different values of "Agent replies", but your question seems to indicate a preference for centralizing the choice of replies within a single trigger, which seems reasonable to me.)
@Felix,
Here is the simple version of liquid which will show "I AM VERY FIRST MESSAGE!" for the first public comment added AFTER descriotion. "I AM SECOND AND ALL FOLLOWING MESSAGES!" will be shown for all following comments.
Note: it won't be rendered if Agent creating a ticket. But will be rendered for the first public comment added after ticket is created.
{% for comment in ticket.public_comments %}
{% if forloop.length < 2 %}I AM VERY FIRST MESSAGE!
{% else %}I AM SECOND AND ALL FOLLOWING MESSAGES!
{% break %}{% endif %}{% endfor %}
Thanks Andrey,
what do you think about this version? (does not work as the assigned "when" is not identified - this should be so easy.)
{% for comment in ticket.public_comments | modulo:3 %}
{% when 0 %}I AM VERY FIRST MESSAGE! - even when creating a ticket.
{% when 1 %} This is another message, number 2.
{% when 2 %} A third version.
{% else %} For any higher amount of tickets.
{% endcase %}
Have you tried that? Liquid appears to be missing some tags.
It doe snot work no...any suggestion?
@jonathan
I *think* that the problem with using ticket.public_comments is that it does not distinguish between agent-written and customer-written comments, so that the count of public comments would not be well defined for your purpose.
The reason it doesn't work is connected syntax errors in the code.
As Jonathan pointed out the "ticket.public_comments" placholder counts ALL public comment regardless of the author. Which may work for some simple use cases.
If you believe that recommendation above doesn't help here then I suggest you define "our first reply" a bit better. Is this the first public comment after decsription that was added by an Agent? Does it have to be assignee, CC or any agent in Zendesk? Do you expect any other public comments added in between description and "first reply"? Where exactly does the liquid code run: trigger, macros?
Hey. Thanks fro taking the time and asking these questions.
Our replies would be the public comments that we make to the customer, the descriptions usually go out as an email as well - so you are right to ask the question. Yes, it could happen that a customer replies to our first message, the "description".
I feel this was very simple when I had it 12 months ago - I think I got it from some comment in this support center. It should just count the amount of our emails going out, three different messages, thats all.
The liquide code goes in dynamic content, which then goes into a macro.
Thanks so much again, sorry for the hassle.
Thank you very much for sharing, nice workaround to get a logic to generate a randomizer.
We use the randomizer to randomly select a banner to display in outgoing e-mail notifications. This banners show different offers (for example "Printer offer - only 299€" or "notebook offer - only 599€").
When a customer replies to an e-mail with a banner, we did not see which banner was previously used, because of the delimiter, which is used to separate old content from new. The new content is added to the ticket as a comment but the old content (with the banner) cannot be checked by triggers.
Is there a way to identify which banner was randomly used before, when the customer replies?
Because if a customer replies only with "Please place an order with 5 of it" - we are not able to recognize the banner which the customer is referring to.
Please sign in to leave a comment.