Example: Integrating the HTTP Target with Slack

Return to top
Have more questions? Submit a request

30 Comments

  • Bart Brosens

    thanks for the great post Steven!

    I was wondering...is there a way to notify a target with the latest comment in a zendesk ticket?

    I don't see it in the available placeholders.

    thx

    Bart

     

    0
  • Nicole Saunders
    Zendesk Community Team

    Hey Bart - 

    You should be able to do so. You just set up the target, and then it's triggers that do the work. More info can be found here: 

    Notifying external targets

    0
  • Molekule

    Great example, how do I add the following variables into the slack post.  I set up a trigger to send all of this via email, but would prefer to have it go to Slack....  Any help on what the JSON code would be? 

    Thanks!

     

    Requester: {{ticket.requester.name}}
    Assignee: {{ticket.assignee.name}}
    Ticket #: {{ticket.id}}
    Rating: {{satisfaction.current_rating}}

    Comment: {{satisfaction.current_comment}}

    1
  • Jessie Schutz
    Zendesk team member

    Hi Jay!

    Rather than sending to email, you need to have it send to the HTTP target you create to send info to Slack. The very last image in the article shows what the JSON looks like. That should get you where you need to go!

    -1
  • Molekule

    @Jessie -

    I know you need to send to HTTP target.  I got that working, but I want to sen other fields from ZD to Slack, like I set up with my email trigger.  See below.  What does the JSON code look like if I want to add these fields?

    Requester: {{ticket.requester.name}}

    Assignee: {{ticket.assignee.name}}
    Ticket #: {{ticket.id}} 
    Rating: {{satisfaction.current_rating}}

    Comment: {{satisfaction.current_comment}}

    1
  • Jessie Schutz
    Zendesk team member

    Hey, Jay! Sorry I misunderstood your question.

    I was able to find some documentation about formatting incoming webhooks in Slack's API resources, so that should help you get started.

    Based on the screenshot example above, it looks like you can use regular ZD placeholders to send that information over, but I'll see about getting one of our Community Moderators in here to verify that for you!

    0
  • Lara Palmer

    @Jay or @Jessie

    Did anybody ever figure out the answer to Jay's question?  I'm trying to do the same thing - add additional fields to what Zendesk sends to Slack.  I tried adding it right in the Zendesk JSON but Slack doesn't interpret it.  I believe I probably have to dork with the JSON URL in the slack webhook as well as the JSON in the Zendesk trigger but there I'm not finding any information on how to manipulate the JSON URL in the slack webhook.

     

    Thanks,

    Lara

    0
  • Lara Palmer

    Never mind:  https://thecoolway.net/2018/01/13/advanced-zendesk-notifications-in-slack-using-incoming-webhooks/

     

    I also see that Zendesk and Slack have collaborated to do a new integration but you have to be a certain level customer with Zendesk and it still seems kind of locked down on what fields you can display.

    1
  • Molekule

    Finally got escalated to T3 support, Garrick killed it and helped me customize JSON to get what i need.   Here's what you need if you want to send CSAT/DSAT notifications to your team via a Slack Channel...Really speeds up the investigation/feedback cycles.

     

    { "text": "DSAT received on {{ticket.url}}, [Assigned to {{ticket.assignee.name}}] [Customer = {{ticket.requester.name}}] [Comment = :\n{{satisfaction.current_comment}}]" }

    3
  • Nicole Saunders
    Zendesk Community Team

    Glad to hear you got the help you needed, Jay! Thanks for sharing the answer. 

    0
  • Dan Ross
    Community Moderator

    For users playing with shaping JSON to send to Slack or other services, you may find https://jsonlint.com/ to be invaluable. You can enter and validate that the JSON is structurally correct, which is handy because if you send bad JSON to Slack, you don't get a ton of information about what broke. 

    4
  • Jessie Schutz
    Zendesk team member

    Thanks for sharing that, Dan!

    0
  • Danny Koss

    Hello. I'm trying to modify the JSON blob of a trigger that is sent to an extension which in turn fires a message to Slack.

    The current JSON which successfully sends info to Slack is:

    {"status": "{{ticket.status}}", "id": "{{ticket.id}}", "updated_at": "{{ticket.updated_at_with_timestamp}}"}

    Oddly, what is generated in Slack does not reflect this information.  The result looks like the following:

    I would like to change the JSON to something like the following, but the extension fails to send anything to Slack:

    {"ticket_id": "{{ticket.id}}","status": "{{ticket.status}}","updated_at": "{{ticket.updated_at_with_timestamp}}","subdomain": "{{ticket.account}}","ticket_latest_comment": "{{ticket.latest_comment}}","updated_by": "{{current_user.name}}"}

    0
  • Dan Ross
    Community Moderator

    Hey Danny,

     

    Do you see anything in your API->Target Failures tab in your settings that correspond to the time you did your test?

    Do you have the Zendesk-built in slack integration installed as well? or just the setup described in the article?

     

     

    0
  • Danny Koss

    Hi Dan.  Yes, there are in fact target failures with status 500 (invalid_ticket_id).

    We did install the Zenesk-built integration, but many of the triggers still rely on the legacy Slack-built integrations if I'm not mistaken.

    0
  • Dan Ross
    Community Moderator

    Hey Danny,

    My hunch is that your extension might be expecting a parameter name of "id" instead of ticket_id", given that your initial JSON worked and the new one doesn't. (one has "id":"{{ticket.id}}" and the other has "ticket_id":"{{ticket.id}}". 

    However, just sending the blob as is in a trigger, (once it works) will generate a pretty simple message.

    If you're looking to mimic the styling you're seeing in the screenshot you included, you might want to look at using the Slack Attachments feature.

     

    Assuming you're posting to an Incoming Webhook target for Slack, here's an example template:

    {  
       "channel":"ENTER DESTINATION CHANNEL NAME OR USER ID HERE (eg:escalation_channel)",
       "icon_emoji":":FAVOURITE EMOJI:",
       "username":"WHAT YOU WANT TO NAME YOUR BOT",
       "attachments":[  
          {  
             "fallback":"You have a reply on ticket #{{ticket.id}}({{ticket.title}}!",
             "pretext":"You have a reply on ticket #{{ticket.id}}({{ticket.title}}!",
             "title":"Click To Open Ticket",
             "title_link":"{{ticket.link}}",
             "color":"(green, yellow, warning, see slack docs for options. )",
             "fields":[  
                {  
                   "title":"Status",
                   "value":"{{ticket.status}}",
                   "short":true
                },
                {  
                   "title":"Ticket Subject",
                   "value":"{{ticket.title}}",
                   "short":true
                },
                {  
                   "title":"Assignee",
                   "value":"{{ticket.assignee.name}}",
                   "short":true
                },
                {  
                   "title":"SOME OTHER FIELD",
                   "value":"{{SOME OTHER PLACEHOLDER}}",
                   "short":true
                }
             ]
          }
       ]
    }

    here's a sample of what that looks like. This screenshot isn't a 1:1 for the fields I've put in the demo above, but it should illustrate the point. 

     

    Hope that helps!

    5
  • Danny Koss

    Thanks, Dan!  You got me going in the right direction.  All is now working as expected.

    2
  • Nick Misewicz

    Hey Steven,

     

    Thank you for this! This is awesome and such a great tutorial Is there a way to compile a daily summary versus the previous 24 hours using this method of the rated tickets? I.e. just a simple count of Good vs. Bad ticket satisfaction comparing the last 48 hours into two timeframes? 

    We use delighted and they have a summary that counts the data (see ex below), and I was wondering if that would be possible:

     

    Look forward to your thoughts.  Even a ticket assignee summary would be awesome as well so each agent can see where they are at day-to-day. 

    0
  • Conza

    Anyone got a template for what Zendesk's official integration with Slack looks like i.e. the JSON for that message? 

    I like its setup, and want to replicate - but with a trigger to a slack channel. And need that.

    1
  • McCabe Tonna
    Community Moderator

    @conza

    this is the "Slack Ticket Trigger" it makes automatically

     

    {
    "ticket_id": "{{ticket.id}}",
    "status": "{{ticket.status}}",
    "updated_at": "{{ticket.updated_at_with_timestamp}}",
    "subdomain": "{{ticket.account}}",
    "ticket_latest_comment": "{{ticket.latest_comment}}",
    "updated_by": "{{current_user.name}}"
    }

    0
  • Arsenio Figueroa

    Is there anyway to only show certain text in the description? For instance could you do a regex to look for a certain word and only display that word?

    0
  • Brett Bowser
    Zendesk Community Team

    Hey Arsenio,

    Any chance you could provide some additional context on what information you'd like displayed? I assume you want specific text from the ticket description to show in Slack?

    0
  • Arsenio Figueroa

    Hi Brett, 

     

    I would like to grab a link out of the description and be able to display it in the slack message.

    0
  • Dan Ross
    Community Moderator

    Hey Arsenio Figueroa

    This might be something you could accomplish using Liquid Templating in your Notify Target action to control what you send to Slack. It's not the most straightforward experience but that might be where I'd start looking.

    https://support.zendesk.com/hc/en-us/articles/203662146-Understanding-Liquid-markup-and-Zendesk-Support


    https://shopify.github.io/liquid/basics/introduction/

    1
  • Casey

    Hey - is there any way to send the content of an internal note that's just been posted in a ticket, to Slack? I am extremely new at JSON and script writing so any information about how to do this would be much appreciated - thank you!

    0
  • Lea Jane Hug

    I spent all day working on getting this to work, I style it to look quite similar to the native Zendesk/Slack integration and if anybody needs it I'm adding the code below, all you need to do is paste it into  Trigger - JSON Body in Zendesk trigger:

     

    { "attachments": [
    {"text": "{{ticket.status}} Ticket from {{ticket.requester.name}} : <https://chainbytes.zendesk.com/agent/tickets/{{ticket.id}}|Ticket#{{ticket.id}}>\n <https://chainbytes.zendesk.com/agent/tickets/{{ticket.id}}|*{{ticket.title}}*>.\n {{ticket.latest_public_comment}}\n Status : <https://chainbytes.zendesk.com/agent/tickets/{{ticket.id}}|{{ticket.status}}>\n Assigned to agent : {{ticket.assignee.name}} "
    } ]
    }

     


    And here is how it will look like:



    What I want to do is to change the color of the attachment line (which is currently grey) as per ticket status to match the Zendesk colors for New, Open, Hold, Pending. But I have no idea how to do that. 

    Can someone help me with how to change the above grey line from Gray to Yellow for New ticket and Red for Open. I guess I need to create separate triggers for every Staus and add code that will display the color as I need it, and that's ok.
    But can anyone help me with what code I would need to add to the one I already have above to assign the color to that attachment line to be for example Yellow? 

    0
  • Dan Ross
    Community Moderator

    Hey Lea Jane Hug

    You can do that in two ways, you can either have a trigger for each status and have a different message setup for each trigger, or you can do it in one trigger using Liquid Markup that tests for the status and then if it meets a condition, send a different message. The latter is more complex to setup but reduces the total number of triggers required. 

    In either case, the attribute you need to set on the Slack message is the attribute for  `color` and then set a hex code color. Some Zendesk colours and the hex codes for them are found here. Some words also work in place of hex codes, like 'good' (for green), 'warning' (yellow), and 'danger' (red), but a hex code offers most control.

    You can also break up the layout a bit without needing to format a /n linebreak if you use the Attachments message structure. Sample of the Attachments layout can be found in Slack's docs here

    Here's an example below!

    {  
    "channel": "#YOURCHANNEL or @USERID",
    "icon_emoji": ":EMOJI:",
    "username": "Zendesk Operators",

    "attachments":
    [
    {
    "fallback":"Ticket from {{ticket.requester.name}}",
    "pretext": "Ticket from {{ticket.requester.name}}",
    "title": "Click To Open Ticket",
    "title_link": "{{ticket.link}}",
    "color": "#2eb886",
    "fields": [
    {
    "title": "Status",
    "value": "{{ticket.status}}",
    "short": true
    },
    {
    "title": "Ticket Subject",
    "value": "{{ticket.title}}",
    "short": true
    },
    {
    "title": "Assignee",
    "value": "{{ticket.assignee.name}}",
    "short": true
    },
    {
    "title": "Last Public Comment",
    "value": "{{ticket.latest_public_comment}}",
    "short": false
    }
    ]
    }
    ]
    }

     

     

     

    1
  • Mirek Kokes

    Hi Zendesk Community team,

    Right now, we have one brand (A) in our Zendesk account and there is a Slack/Zendesk integration, which provides details about tickets, see here

    We are about to set up a new additional brand in our Zendesk (B) and we would like to differentiate in Slack between tickets coming from those brands:

    • Zendesk ticket brand=A -> Slack channel e.g. #A-brand
    • Zendesk ticket brand=B -> Slack channel e.g. #B-brand

    Is it possible to set this up? If yes, can you please provide more information?

    Thanks

    Mirek

    0
  • Jacob J Christensen
    Community Moderator

    Hi Mirek Kokes

    That should be doable. You would need an HTTP target for each of your Slack channels, and a trigger for each of your brands - specifying the conditions under which you want to push a message, e.g. if Ticket is created + Brand is A, then notify target A (your HTTP target for the Brand A channel).

    Let me know if you need more details than that - hope this helps!

    0
  • Lea Jane Hug

    Hey Dan Ross That worked perfectly!
    I created separate triggers for every status change, assigned "zendesk colors" to every status, and adjusted it a bit to give us the info we needed. And it's really good, I cant tell the difference from the native integration. Thank you so much!

    One difference is that i cant make it show "Read more" for placeholder: 

    "{{ticket.latest_public_comment}}"


    It keeps showing the entire response (which including the signature is a bit overwhelming at times), do you have any idea how to make it short and add read more for expanding to the entire comment?  

    0

Please sign in to leave a comment.

Powered by Zendesk