Send out different notification messages using liquid Follow

Comments

23 comments

  • Avatar
    Serge Payette

    Thanks for sharing @Andrey.

  • Avatar
    Terry Knox

    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? 

  • Avatar
    Terry Knox (Edited )

    Pretty sure I've sorted this out now - just removed all carriage returns and spaces in the Liquid Markup and it seems to work. 

  • Avatar
    Jessie - Community Manager

    Great, Terry! I'm glad you were able to get it sorted out, and thanks for sharing the solution. :)

  • Avatar
    Sam Tilin

    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? 

  • Avatar
    Andrey Sarapulov

    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.

     

  • Avatar
    Sam Tilin

    @Andrey Thanks! I'll work on that

  • Avatar
    Andreas Schuster

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

    {% assign current_time = 'now' | date: "%L" %}
    {% assign r = current_time | modulo:4 %}
    {% case r %}
    {% when 0 %}
    Thank you for reaching out to us,
    {% when 1 %}
    Thank you for contacting us,
    {% when 2 %}
    Thank you for writing us,
    {% when 3 %}
    Thank you for dropping us a message,
    {% endcase %}

    The placeholder %L gives you the current milliseconds of the UNIX timestamp, e.g. 674.

  • Avatar
    Christopher Rehn

    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?

  • Avatar
    Andrey Sarapulov

    @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

  • Avatar
    Andreas Schuster

    @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 😕

  • Avatar
    Andrey Sarapulov

    @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 ^ ?

  • Avatar
    Felix

    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? 

  • Avatar
    Jessie - Community Manager

    Hey Felix!

    I'll check to see if any of our Community Moderators can help with this. Stand by!

  • Avatar
    Jonathan March

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

  • Avatar
    Andrey Sarapulov

    @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 %}

  • Avatar
    Felix (Edited )

    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 %}

  • Avatar
    Andrey Sarapulov

    Have you tried that? Liquid appears to be missing some tags.

  • Avatar
    Felix

    It doe snot work no...any suggestion? 

    @jonathan

  • Avatar
    Jonathan March

    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.

  • Avatar
    Andrey Sarapulov

    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?

  • Avatar
    Felix

    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. 

  • Avatar
    Oliver Knigge

    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.

Powered by Zendesk