Zendesk help center in iOS
using Zendesk Swift API providers
Zendesk is a great tool to provide a ticketing system to our users, as well as a knowledge base articles, aka. FAQs. From my experience implementing it in iOS, Zendesk
provides UI components that allow us rapidly include a help center in our projects. However, when we want the UI to look differently, it gets a bit more complicated since modifying the styles or simply having a different custom behavior is not straightforward nor scalable whatsoever. In this article, I am showing how to use Zendesk
service providers to build a layer on top, and separate support system concerns.
Of course, the benefits of creating a new layer are clear, it’s possible to customize UI and have more flexibility in the way our user support system behaves. On the other hand, it costs some time and effort to implement. But this is what I am here for, I am showing you the Zendesk Service Provider
APIs you might probably need to use along with this feature implementation.
A little disclaimer before we crack on the tutorial. I am not related to Zendesk in any way. All the information and code I have got come from their public developer site. This article brings a real-project example that might help other developers to achieve the same goal quickly.
Let’s crate the protocols first
The idea behind using protocols early in the process is to have more testability, and to easily change providers, imagine that tomorrow we decide not to use Zendesk anymore, the changes required to implement the new provider will have minimal impact on the project.
Support Provider
This protocol provides a way to initialize the library, which might look useless, but it becomes handy for testing purposes.
Support Help Center Provider
This protocol will provide the FAQs logic, to list all articles, search, and, vote down or vote up an article. Naturally, many more functionalities can be added, but this is the basic approach.
Support Request Provider
This protocol manages all logic related to user requests, such as creating requests, fetching requests, list comments on a request, and read a comment on a request. The term UserRequest
is also known as UserTicket
, but for the sake of this article and to keep it close to what Zendesk provides, I am calling it Request
, too.
Concrete implementations
Alright! With our protocols in place, it’s time to add our concrete Zendesk implementations, in which we will use what the library offers. Since we used protocols to dictate how the feature would behave, all logic related to Zendesk or any other ticketing system, will remain isolated, as well as, easy to track test, debug, and replace if needed.
Initialize Zendesk
This is how we set up the Zendesk library, as you can see in the next snippet, this code will be used from the AppDelegate
or any dependency injection object you use.
Notice, I treat the supportProvider
object as a SupportProvider
type even though I instantiate it as a ZendeskSupportProvider
object, this is to talk in terms of the protocol and not the concrete implementation.
Zendesk Support Help Center Provider
Zendesk Support Request Provider
Thanks for reading. I hope you have enjoyed this small tutorial, and if it was useful for you, don’t be shy to 👏 on this article. See you next time.