Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to set Zendesk custom fields and form template #1170

Merged
merged 8 commits into from
Oct 13, 2023

Conversation

AgaDufrat
Copy link
Contributor

@AgaDufrat AgaDufrat commented Aug 24, 2023

Context

The current Content Change Request form also doesn't make the most of Zendesk. Making better use of custom fields would allow content design teams to improve internal reporting (e.g. improvement work tickets vs factual inaccuracy tickets).
The form template and custom fields were created in the UI.

Trello card

What

  • Adds ability to set custom fields and form template in Zendesk
  • Sets the following custom fields for Content change request tickets:
    • [CR] Reason for the request (required)
    • [CR] Subject Area(required)
    • [CR] Deadline
    • [CR] Do not publish before
    • [CR] Deadline (time)
    • [CR] Do not publish before (time)
  • Sets 'Content Request' form template for Content change request tickets
Before After
Screenshot 2023-08-24 at 10 23 52 Screenshot 2023-08-23 at 15 16 11

Ticket examples:

Review notes

  • Best reviewed commit by commit (see message for more details)
  • Since the custom fields information needs to be hardcoded, I decided to use a YAML file to store it. Loading ruby classes from a YAML file introduces a level of abstraction but has the following benefits:
    • allows us to store all information about the Zendesk Custom fields in a YAML file (the app doesn't seem to have access to the custom fields end point via Zendesk API)
    • specific Ticket classes don't need to know about field type
    • CustomField class is not responsible for validating/formatting values of different types
    • makes it easy to extend should we want to populate other type of fields such as multi-select.

How to test it


⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

@AgaDufrat AgaDufrat changed the title Add functionality to set Zendesk custom fields Add functionality to set Zendesk custom fields and form template Aug 24, 2023
Copy link
Contributor

@robinjam robinjam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing Aga 🌟

Couple of nitpicks (plus the question above), but it's looking great

config/zendesk/custom_fields_data.yml Outdated Show resolved Hide resolved
spec/fixtures/zendesk_custom_fields_data.yml Outdated Show resolved Hide resolved
spec/models/zendesk/custom_field_type/date_field_spec.rb Outdated Show resolved Hide resolved
spec/models/zendesk/custom_field_type/date_field_spec.rb Outdated Show resolved Hide resolved
spec/models/zendesk/custom_field_type/date_field_spec.rb Outdated Show resolved Hide resolved
@AgaDufrat AgaDufrat force-pushed the zendesk-custom-fields branch 2 times, most recently from 3338386 to 433abc9 Compare August 25, 2023 15:44
Copy link
Contributor

@robinjam robinjam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work!

The class didn't have a unit test.
Each class is responsible for validation and formatting of the value.

The naming in the Zendesk UI and API reference is inconsistent.  Decided to
follow the UI convention, as we are getting the values from a User support
agent who is using the UI [^1].  Types that are not currently used were not
included but the modules should be easy to extend.

We are currently using the following custom field types:
    - Text: default Zendesk type
    - Date: only the date (formatted as a ISO 8601 string) and omit the time.
      The form allows to submit dated in different valid formats. We need to
format and validate it, otherwise `ZendeskAPI::Error::RecordInvalid` will be
raised and the ticket will not be submitted. Since ‘Date’ class is already
defined on the main object, `DateField` is used.
    - Drop-down: the option's tag name for the value property, not the option
      text displayed in the list. We need to map the displayed text to a name
tag.

See [^2] for more examples and details.

[^1]: https://support.zendesk.com/hc/en-us/articles/4408838961562
[^2]: https://developer.zendesk.com/documentation/ticketing/managing-tickets/creating-and-updating-tickets/#setting-custom-field-values
We want to start populating custom fields in Zendesk.

To set the value of one or more custom fields in a ticket, we need to specify
an array of objects consisting of `id` and `value` properties. [^1]

* ID integers
Most Zendesk Support resources, such as tickets and users, are identified by
the integer specified by the id attribute of API responses. The term refers to
the JSON numeric type, not a C-like int data type.  The default numeric type in
JavaScript, Ruby, Python, and PHP is sufficient to represent Zendesk Support ID
integers.
Tested that String also work as an ID but decided to follow Zendesk
documentation on this.
ID formatting curtesy of rubocop:
   Style/NumericLiterals: Use underscores(_) as thousands separator and
separate every 3 digits with them.
(https://rubystyle.guide#underscores-in-numerics)

* Value
Value depends on the custom field type. Validation and formatting is preformed
by each class.

This particular implementation (reading ruby classes from a YAML file)
introduces a level of abstraction but has the following benefits:
- allows us to store all information about the Zendesk Custom fields in a YAML
  file (the app doesn't seem to have access to the custom fields end point via
Zendesk API)
- specific Ticket classes don't need to know about the type of field
- specific Ticket classes don't need to know about field type
- CustomField class is not responsible for validating/formatting values of
  different types
- makes it easy to extend should we want to populate other type of fields such
  as multi-select.

[^1]: https://developer.zendesk.com/documentation/ticketing/managing-tickets/creating-and-updating-tickets/#setting-custom-field-values
We want to start populating custom fields if they are defined for the Zendesk
Ticket.

Name: custom_fields
Type: array
Read-only: false
Mandatory: fasle
Description: Custom fields for the ticket.
See Setting custom field values:
https://developer.zendesk.com/documentation/ticketing/managing-tickets/creating-and-updating-tickets/#setting-custom-field-values

https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#json-format
The custom fields were created in the Zendesk UI by a user with admin
permissions. We had to obtain:
- custom fields ids
- name tag for drop down options
We need to map drop down option description to a name tag configured in
Zendesk.  If a description is changed or an option added in the UI but not the
config/zendesk/custom_fields_data.yml the custom fields will stop getting
populated correctly.
The information is included in the custom fields so this removes duplicate
information as requested by a Content Designer.  It removes the
base_comment_snippets from ZendeskTicket. The specific Ticket classes can
define whether the information is passed in the body or custom fields.  It also
moves the [Reason for time constraint] at the end of the ticket body.
Normally the Zendesk tickets default to the "Default Ticket Form. We want to
render "Content Request" form because some information in the Content change
request tickets is included only in the custom fields (not in the body). The
Zendesk user might not see this information if they don’t know to switch to the
correct form template. Therefore we want to render the correct form for this
ticket.

Name: ticket_form_id
Type: integer
Read-only: false
Mandatory: false
Description: Enterprise only. The id of the ticket form to render for the ticket

From the API reference: https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#json-format
@AgaDufrat AgaDufrat merged commit 62a4dbd into main Oct 13, 2023
5 checks passed
@AgaDufrat AgaDufrat deleted the zendesk-custom-fields branch October 13, 2023 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants