Set local time zone for voice and text end-users using their phone numbers
Challenge
End-users created by incoming phone calls, voicemail or text (SMS) are assigned your Zendesk account's default time zone--not their own local time zone. This can be problematic if local times are important for your reporting.
Solution
Use a trigger with Liquid code to identify the country code in the end-user's phone number, and send a request to the Users API to set the user's local time zone based off the country code. This isn't an ideal solution for users in countries with multiple time zones, and it's also not ideal in that users could be calling from a number based in a different country, but I think this is the best solution we have.
Steps
- If you have not done so already, turn on API access in your Zendesk account (Admin > Channels > API). Token access is suggested.
- Setup an HTTP target extension by clicking Admin > Settings > Extensions > add target. Setup the HTTP target as shown below. Note that the URL starts with https://[yourSubDomain]/zendesk.com... If you are using token access, the password is the API token you setup in step 1.
- Add a new trigger by clicking Admin > Business Rules > Triggers > Add trigger. Setup the trigger as shown below. Modify the Liquid code with the country codes of your end-users, and the associated city names exactly as they're shown in the Admin > Settings > Account > Localization > Time zone drop-down but without the GMT calculation. Note that you'll need to choose one city (time zone) to associate with each country code.
Here's the Liquid code again (with a few additional countries):
{%- if ticket.requester.phone contains "+60" -%}
{%- assign timeZone = "Kuala Lumpur" -%}
{%- elsif ticket.requester.phone contains "+977" -%}
{%- assign timeZone = "Kathmandu" -%}
{%- elsif ticket.requester.phone contains "+880" -%}
{%- assign timeZone = "Dhaka" -%}
{%- elsif ticket.requester.phone contains "+91" -%}
{%- assign timeZone = "New Delhi" -%}
{%- elsif ticket.requester.phone contains "+62" -%}
{%- assign timeZone = "Jakarta" -%}
{%- endif -%}
{%- if timeZone -%}
{
"user": {
"time_zone": "{{timeZone}}"
}
}
{%- endif -%}
That's it. If you know of any ways to improve this, please let us know.
-
Thanks for sharing this, Josh!
-
Amazing @Josh, I love it!
Please sign in to leave a comment.
2 Comments