diff --git a/README.md b/README.md index 7ff5069..ec00623 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,200 @@ -# module-ballerinax-zendesk -The Ballerina Zendesk Connector facilitates direct integration and automation between Ballerina applications and the Zendesk platform. This connector is designed for developers requiring efficient integration solutions to extend customer support functionalities within Ballerina applications, minimizing complexity in API communication. +# Ballerina Zendesk connector + +[![Build](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/ci.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/ci.yml) +[![Trivy](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/trivy-scan.yml) +[![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-zendesk/actions/workflows/build-with-bal-test-graalvm.yml) +[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-zendesk.svg)](https://github.com/ballerina-platform/module-ballerinax-zendesk/commits/master) +[![GitHub Issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-library/module/github.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-library/labels/module%2Fgithub) + +[Zendesk](https://www.zendesk.com/) is a customer service software company that provides a cloud-based customer support platform. It is designed to offer a seamless and efficient customer service experience, enabling businesses to manage customer interactions across multiple channels, including email, chat, phone, and social media. + +The Ballerina Zendesk Connector allows developers to interact with the [Zendesk REST API V2](https://developer.zendesk.com/api-reference/ticketing/introduction/), making it easier to integrate customer support features into Ballerina applications. This connector enables the automation of Zendesk Support operations such as ticket management, user and organization management, and more. + +## Setup guide + +To use the Zendesk Connector in Ballerina, you must have a Zendesk account and an API token for authentication. Follow the steps below to set up the connector with your Zendesk account. If you don't have an account, you can create one by visiting [Zendesk Sign Up page](https://www.zendesk.com/register/) and completing the registration process. + +### Step 1: Log in to Zendesk + +1. Sign in to your Zendesk account. +2. Navigate to the dashboard. + +### Step 2: Access admin center + +1. Click on the **Settings** icon in the sidebar. +2. Click on **Go to Admin Center**. + + ![Zendesk Admin Center](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/1-admin-center.png) + +### Step 3: Manage API tokens + +1. In the Admin Center, click on **Apps and integrations**. +2. Click on **Connections** under the **Connections** section. +3. Click on **Create connection** to create a new connection. + + ![Zendesk Connection Settings](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/2-connection-settings.png) + +### Step 4: Configure & generate the token + +When creating a new connection, you will be prompted to provide the following details: + +- **Connection name**: A descriptive name for the connection. +- **Authentication type**: Possible options are `API key`, `Basic Auth`, `Bearer Token`, and `OAuth 2.0`. +- **Allowed domain**: The domain that the connection is allowed to access. You can use a wildcard to allow requests made + to any subdomain by adding an asterisk (*) at the start. + + ![Zendesk Connection Configuration](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/3-connection-configuration.png) + +> **Note:** The rest of the fields (e.g. `username`, `password`, `token`) will appear based on the selected authentication type. + +## Quickstart + +To begin using the `Zendesk` connector in your Ballerina application, you'll need to follow these steps: + +### Step 1: Import the connector + +First, import the `ballerinax/zendesk` package into your Ballerina project. + +```ballerina +import ballerinax/zendesk; +``` + +### Step 2: Instantiate a new connector + +Create a `zendesk:Configuration` object with your domain and API token, and initialize the connector. + +```ballerina +zendesk:ConnectionConfig zendeskConfig = { + auth: { + username: "", + password: "" + } +}; + +zendesk:Client zendesk = check new (zendeskConfig); +``` + +### Step 3: Invoke the connector operation + +Utilize the connector's operations to manage tickets, users, organizations, etc. + +#### Create a ticket + +```ballerina +zendesk:TicketCreateRequest ticket = { + ticket: { + subject: "Subject of the ticket", + comment: { + body: "Body of the ticket comment" + } + } +}; + +zendesk:TicketResponse createResponse = check zendesk->/api/v2/tickets.post(ticket); +``` + +#### List tickets + +```ballerina +zendesk:TicketsResponse tickets = check zendesk->/api/v2/tickets; +``` + +## Examples + +The `Zendesk` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/), covering the following use cases: + +1. [Multi channel support integration](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/multi-channel-support-integration) - Integrate Zendesk with multiple customer support channels to streamline ticket management. +2. [Customer satisfaction survey analysis](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/customer-satisfaction-survey-analysis) - Analyze customer satisfaction survey responses to improve support services. + + +## Issues and projects + +The **Issues** and **Projects** tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library [parent repository](https://github.com/ballerina-platform/ballerina-library). + +This repository only contains the source code for the package. + +## Build from the source + +### Prerequisites + +1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources: + + * [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) + * [OpenJDK](https://adoptium.net/) + + > **Note:** After installation, remember to set the `JAVA_HOME` environment variable to the directory where JDK was installed. + +2. Download and install [Ballerina Swan Lake](https://ballerina.io/). + +3. Download and install [Docker](https://www.docker.com/get-started). + + > **Note**: Ensure that the Docker daemon is running before executing any tests. + +### Build options + +Execute the commands below to build from the source. + +1. To build the package: + + ```bash + ./gradlew clean build + ``` + +2. To run the tests: + + ```bash + ./gradlew clean test + ``` + +3. To build the without the tests: + + ```bash + ./gradlew clean build -x test + ``` + +4. To run tests against different environment: + + ```bash + ./gradlew clean test -Pgroups= + ``` + +5. To debug package with a remote debugger: + + ```bash + ./gradlew clean build -Pdebug= + ``` + +6. To debug with the Ballerina language: + + ```bash + ./gradlew clean build -PbalJavaDebug= + ``` + +7. Publish the generated artifacts to the local Ballerina Central repository: + + ```bash + ./gradlew clean build -PpublishToLocalCentral=true + ``` + +8. Publish the generated artifacts to the Ballerina Central repository: + + ```bash + ./gradlew clean build -PpublishToCentral=true + ``` + +## Contribute to Ballerina + +As an open-source project, Ballerina welcomes contributions from the community. + +For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). + +## Code of conduct + +All the contributors are encouraged to read the [Ballerina Code of Conduct](https://ballerina.io/code-of-conduct). + +## Useful links + +* For more information go to the [`zendesk` package](https://lib.ballerina.io/ballerinax/zendesk/latest). +* For example demonstrations of the usage, go to [Ballerina By Examples](https://ballerina.io/learn/by-example/). +* Chat live with us via our [Discord server](https://discord.gg/ballerinalang). +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f38bac9..68c6a44 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ distribution = "2201.8.6" org = "ballerinax" name = "zendesk" -version = "0.1.0" +version = "1.0.0" license = ["Apache-2.0"] authors = ["Ballerina"] keywords = ["zendesk", "CRM", "CSM", "Support/Customer Support", "Cost/Freemium"] diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 92ac37e..2070841 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -302,7 +302,7 @@ modules = [ [[package]] org = "ballerinax" name = "zendesk" -version = "0.1.0" +version = "1.0.0" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "log"}, diff --git a/ballerina/Module.md b/ballerina/Module.md index e69de29..96395eb 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -0,0 +1,101 @@ +# Ballerina Zendesk connector + +[Zendesk](https://www.zendesk.com/) is a customer service software company that provides a cloud-based customer support platform. It is designed to offer a seamless and efficient customer service experience, enabling businesses to manage customer interactions across multiple channels, including email, chat, phone, and social media. + +The Ballerina Zendesk Connector allows developers to interact with the [Zendesk REST API V2](https://developer.zendesk.com/api-reference/ticketing/introduction/), making it easier to integrate customer support features into Ballerina applications. This connector enables the automation of Zendesk Support operations such as ticket management, user and organization management, and more. + +## Setup guide + +To use the Zendesk Connector in Ballerina, you must have a Zendesk account and an API token for authentication. Follow the steps below to set up the connector with your Zendesk account. If you don't have an account, you can create one by visiting [Zendesk Sign Up page](https://www.zendesk.com/register/) and completing the registration process. + +### Step 1: Log in to Zendesk + +1. Sign in to your Zendesk account. +2. Navigate to the dashboard. + +### Step 2: Access admin center + +1. Click on the **Settings** icon in the sidebar. +2. Click on **Go to Admin Center**. + + ![Zendesk Admin Center](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/1-admin-center.png) + +### Step 3: Manage API tokens + +1. In the Admin Center, click on **Apps and integrations**. +2. Click on **Connections** under the **Connections** section. +3. Click on **Create connection** to create a new connection. + + ![Zendesk Connection Settings](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/2-connection-settings.png) + +### Step 4: Configure & generate the token + +When creating a new connection, you will be prompted to provide the following details: + +- **Connection name**: A descriptive name for the connection. +- **Authentication type**: Possible options are `API key`, `Basic Auth`, `Bearer Token`, and `OAuth 2.0`. +- **Allowed domain**: The domain that the connection is allowed to access. You can use a wildcard to allow requests made + to any subdomain by adding an asterisk (*) at the start. + + ![Zendesk Connection Configuration](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/3-connection-configuration.png) + +> **Note:** The rest of the fields (e.g. `username`, `password`, `token`) will appear based on the selected authentication type. + +## Quickstart + +To begin using the `Zendesk` connector in your Ballerina application, you'll need to follow these steps: + +### Step 1: Import the connector + +First, import the `ballerinax/zendesk` package into your Ballerina project. + +```ballerina +import ballerinax/zendesk; +``` + +### Step 2: Instantiate a new connector + +Create a `zendesk:Configuration` object with your domain and API token, and initialize the connector. + +```ballerina +zendesk:ConnectionConfig zendeskConfig = { + auth: { + username: "", + password: "" + } +}; + +zendesk:Client zendesk = check new (zendeskConfig); +``` + +### Step 3: Invoke the connector operation + +Utilize the connector's operations to manage tickets, users, organizations, etc. + +#### Create a ticket + +```ballerina +zendesk:TicketCreateRequest ticket = { + ticket: { + subject: "Subject of the ticket", + comment: { + body: "Body of the ticket comment" + } + } +}; + +zendesk:TicketResponse createResponse = check zendesk->/api/v2/tickets.post(ticket); +``` + +#### List tickets + +```ballerina +zendesk:TicketsResponse tickets = check zendesk->/api/v2/tickets; +``` + +## Examples + +The `Zendesk` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/), covering the following use cases: + +1. [Multi channel support integration](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/multi-channel-support-integration) - Integrate Zendesk with multiple customer support channels to streamline ticket management. +2. [Customer satisfaction survey analysis](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/customer-satisfaction-survey-analysis) - Analyze customer satisfaction survey responses to improve support services. diff --git a/ballerina/Package.md b/ballerina/Package.md index e69de29..96395eb 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -0,0 +1,101 @@ +# Ballerina Zendesk connector + +[Zendesk](https://www.zendesk.com/) is a customer service software company that provides a cloud-based customer support platform. It is designed to offer a seamless and efficient customer service experience, enabling businesses to manage customer interactions across multiple channels, including email, chat, phone, and social media. + +The Ballerina Zendesk Connector allows developers to interact with the [Zendesk REST API V2](https://developer.zendesk.com/api-reference/ticketing/introduction/), making it easier to integrate customer support features into Ballerina applications. This connector enables the automation of Zendesk Support operations such as ticket management, user and organization management, and more. + +## Setup guide + +To use the Zendesk Connector in Ballerina, you must have a Zendesk account and an API token for authentication. Follow the steps below to set up the connector with your Zendesk account. If you don't have an account, you can create one by visiting [Zendesk Sign Up page](https://www.zendesk.com/register/) and completing the registration process. + +### Step 1: Log in to Zendesk + +1. Sign in to your Zendesk account. +2. Navigate to the dashboard. + +### Step 2: Access admin center + +1. Click on the **Settings** icon in the sidebar. +2. Click on **Go to Admin Center**. + + ![Zendesk Admin Center](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/1-admin-center.png) + +### Step 3: Manage API tokens + +1. In the Admin Center, click on **Apps and integrations**. +2. Click on **Connections** under the **Connections** section. +3. Click on **Create connection** to create a new connection. + + ![Zendesk Connection Settings](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/2-connection-settings.png) + +### Step 4: Configure & generate the token + +When creating a new connection, you will be prompted to provide the following details: + +- **Connection name**: A descriptive name for the connection. +- **Authentication type**: Possible options are `API key`, `Basic Auth`, `Bearer Token`, and `OAuth 2.0`. +- **Allowed domain**: The domain that the connection is allowed to access. You can use a wildcard to allow requests made + to any subdomain by adding an asterisk (*) at the start. + + ![Zendesk Connection Configuration](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-zendesk/master/docs/setup/resources/3-connection-configuration.png) + +> **Note:** The rest of the fields (e.g. `username`, `password`, `token`) will appear based on the selected authentication type. + +## Quickstart + +To begin using the `Zendesk` connector in your Ballerina application, you'll need to follow these steps: + +### Step 1: Import the connector + +First, import the `ballerinax/zendesk` package into your Ballerina project. + +```ballerina +import ballerinax/zendesk; +``` + +### Step 2: Instantiate a new connector + +Create a `zendesk:Configuration` object with your domain and API token, and initialize the connector. + +```ballerina +zendesk:ConnectionConfig zendeskConfig = { + auth: { + username: "", + password: "" + } +}; + +zendesk:Client zendesk = check new (zendeskConfig); +``` + +### Step 3: Invoke the connector operation + +Utilize the connector's operations to manage tickets, users, organizations, etc. + +#### Create a ticket + +```ballerina +zendesk:TicketCreateRequest ticket = { + ticket: { + subject: "Subject of the ticket", + comment: { + body: "Body of the ticket comment" + } + } +}; + +zendesk:TicketResponse createResponse = check zendesk->/api/v2/tickets.post(ticket); +``` + +#### List tickets + +```ballerina +zendesk:TicketsResponse tickets = check zendesk->/api/v2/tickets; +``` + +## Examples + +The `Zendesk` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/), covering the following use cases: + +1. [Multi channel support integration](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/multi-channel-support-integration) - Integrate Zendesk with multiple customer support channels to streamline ticket management. +2. [Customer satisfaction survey analysis](https://github.com/ballerina-platform/module-ballerinax-zendesk/tree/master/examples/customer-satisfaction-survey-analysis) - Analyze customer satisfaction survey responses to improve support services. diff --git a/docs/setup/resources/1-admin-center.png b/docs/setup/resources/1-admin-center.png new file mode 100644 index 0000000..b48216a Binary files /dev/null and b/docs/setup/resources/1-admin-center.png differ diff --git a/docs/setup/resources/2-create-connection.png b/docs/setup/resources/2-create-connection.png new file mode 100644 index 0000000..18b85c4 Binary files /dev/null and b/docs/setup/resources/2-create-connection.png differ diff --git a/docs/setup/resources/3-connection-configuration.png b/docs/setup/resources/3-connection-configuration.png new file mode 100644 index 0000000..4098b79 Binary files /dev/null and b/docs/setup/resources/3-connection-configuration.png differ diff --git a/examples/customer-satisfaction-survey-analysis/.github/README.md b/examples/customer-satisfaction-survey-analysis/.github/README.md new file mode 120000 index 0000000..862f694 --- /dev/null +++ b/examples/customer-satisfaction-survey-analysis/.github/README.md @@ -0,0 +1 @@ +../Zendesk customer satisfaction survey analysis.md \ No newline at end of file diff --git a/examples/customer-satisfaction-survey-analysis/Ballerina.toml b/examples/customer-satisfaction-survey-analysis/Ballerina.toml new file mode 100644 index 0000000..659074e --- /dev/null +++ b/examples/customer-satisfaction-survey-analysis/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "zendesk" +name = "customer_satisfaction_survey_analysis" +version = "0.1.0" +distribution = "2201.8.6" diff --git a/examples/customer-satisfaction-survey-analysis/Zendesk customer satisfaction survey analysis.md b/examples/customer-satisfaction-survey-analysis/Zendesk customer satisfaction survey analysis.md new file mode 100644 index 0000000..d639062 --- /dev/null +++ b/examples/customer-satisfaction-survey-analysis/Zendesk customer satisfaction survey analysis.md @@ -0,0 +1,30 @@ +# Zendesk customer satisfaction survey analysis + +This use case demonstrates how the Zendesk REST API v2 can be utilized to improve customer service quality by +analyzing feedback from satisfaction surveys sent after resolving support tickets. The example involves a sequence +of actions that leverage the Zendesk REST API to automate and streamline these efforts. + +## Prerequisites + +### 1. Setup Zendesk account + +Refer to the [Setup guide](https://central.ballerina.io/ballerinax/zendesk/latest#setup-guide) to set up your zendesk +account, if you do not have one. + +### 2. Configuration + +Update your Zendesk account related configurations in the `Config.toml` file in the example root directory: + +```toml +zedeskDomain = "" +username = "" +password = "" +``` + +## Run the example + +Execute the following command to run the example: + +```ballerina +bal run +``` diff --git a/examples/customer-satisfaction-survey-analysis/main.bal b/examples/customer-satisfaction-survey-analysis/main.bal new file mode 100644 index 0000000..0cb0a6d --- /dev/null +++ b/examples/customer-satisfaction-survey-analysis/main.bal @@ -0,0 +1,50 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerinax/zendesk; + +// Configuration for Zendesk API access +configurable string zendeskDomain = ?; +configurable string username = ?; +configurable string password = ?; + +public function main() returns error? { + // Base URL for Zendesk API + string baseUrl = string `https://${zendeskDomain}.zendesk.com`; + // Create a client object to interact with Zendesk + zendesk:Client zendesk = check new ({auth: {username, password}}, baseUrl); + + // Fetch solved tickets + zendesk:TicketsResponse solvedTicketsResponse = check zendesk->/api/v2/tickets(); + zendesk:TicketObject[] tickets = solvedTicketsResponse?.tickets ?: []; + + foreach zendesk:TicketObject ticket in tickets { + int ticketId = ticket?.id ?: -1; + io:println("Processing Ticket: ", ticketId); + + // Send satisfaction survey for each solved ticket + if ticket.status == "solved" { + zendesk:SatisfactionRatingResponse _ = check zendesk->/api/v2/tickets/[ticketId]/satisfaction_rating.post; + } + } + + // Optionally, fetch and analyze satisfaction ratings + zendesk:SatisfactionRatingsResponse ratingsResponse = check zendesk->/api/v2/satisfaction_ratings; + foreach var rating in ratingsResponse?.satisfaction_ratings ?: [] { + io:println("Rating: ", rating.score); + } +} diff --git a/examples/multi-channel-support-integration/.github/README.md b/examples/multi-channel-support-integration/.github/README.md new file mode 120000 index 0000000..fc9d38f --- /dev/null +++ b/examples/multi-channel-support-integration/.github/README.md @@ -0,0 +1 @@ +../Zendesk multi channel support integration.md \ No newline at end of file diff --git a/examples/multi-channel-support-integration/Ballerina.toml b/examples/multi-channel-support-integration/Ballerina.toml new file mode 100644 index 0000000..8e3c618 --- /dev/null +++ b/examples/multi-channel-support-integration/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "zendesk" +name = "multi_channel_support_integration" +version = "0.1.0" +distribution = "2201.8.6" diff --git a/examples/multi-channel-support-integration/Zendesk multi channel support integration.md b/examples/multi-channel-support-integration/Zendesk multi channel support integration.md new file mode 100644 index 0000000..1c90e12 --- /dev/null +++ b/examples/multi-channel-support-integration/Zendesk multi channel support integration.md @@ -0,0 +1,31 @@ +# Zendesk multi-channel support integration + +This use case demonstrates how the Zendesk REST API v2 can be utilized to consolidate support requests from multiple +channels into a single platform, automating the process of ticket creation, assignment, and initial customer +communication. By streamlining this process, companies can ensure a consistent and efficient support experience for +their customers, regardless of the communication channel used. + +## Prerequisites + +### 1. Setup Zendesk account + +Refer to the [Setup guide](https://central.ballerina.io/ballerinax/zendesk/latest#setup-guide) to set up your zendesk +account, if you do not have one. + +### 2. Configuration + +Update your Zendesk account related configurations in the `Config.toml` file in the example root directory: + +```toml +zedeskDomain = "" +username = "" +password = "" +``` + +## Run the example + +Execute the following command to run the example: + +```ballerina +bal run +``` diff --git a/examples/multi-channel-support-integration/main.bal b/examples/multi-channel-support-integration/main.bal new file mode 100644 index 0000000..0ff8ab6 --- /dev/null +++ b/examples/multi-channel-support-integration/main.bal @@ -0,0 +1,68 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerinax/zendesk; + +// Configuration for the Zendesk client +configurable string zendeskDomain = ?; +configurable string username = ?; +configurable string password = ?; + +public function main() returns error? { + // Base URL for Zendesk API + string baseUrl = string `https://${zendeskDomain}.zendesk.com`; + // Create a client object to interact with Zendesk + zendesk:Client zendesk = check new ({auth: {username, password}}, baseUrl); + + // Simulate fetching an inquiry from a multi-channel support aggregation endpoint + // In a real-world scenario, this could be replaced with actual API calls to various platforms + string inquiryDescription = "Customer inquiry from [Channel Name] regarding [Issue Summary]"; + string inquirySubject = "Multi-Channel Support Inquiry"; + + // Step 1: Create a ticket in Zendesk for the inquiry + zendesk:TicketCreateRequest ticketCreateRequest = { + ticket: { + subject: inquirySubject, + comment: { + body: inquiryDescription + }, + priority: "normal" + } + }; + + zendesk:TicketResponse createTicketResponse = check zendesk->/api/v2/tickets.post(ticketCreateRequest); + int ticketId = createTicketResponse?.ticket?.id ?: -1; + io:println("Ticket Created: ", ticketId); + + // Simulate a condition to update the ticket's status (e.g., inquiry addressed) + // This is a simplified example. In a real-world application, you might check for updates or responses from the customer or support agents + string updateDescription = "Inquiry has been addressed by the support team."; + + zendesk:TicketUpdateRequest ticketUpdateRequest = { + ticket: { + status: "solved", + comment: { + body: updateDescription, + 'public: true + } + } + }; + + // Step 2: Update the ticket's status to 'solved' + zendesk:TicketUpdateResponse updateTicketResponse = check zendesk->/api/v2/tickets/[ticketId].put(ticketUpdateRequest); + io:println("Ticket Updated: ", updateTicketResponse?.ticket?.id); +}