generated from cording12/next-fast-turbo
-
Notifications
You must be signed in to change notification settings - Fork 494
feat: Add Zendesk connector integration #243
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
surfsense_backend/alembic/versions/15_add_zendesk_connector_enums.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Add ZENDESK_CONNECTOR to enums | ||
|
||
Revision ID: 15 | ||
Revises: 14 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "15" | ||
down_revision: str | None = "14" | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Safely add 'ZENDESK_CONNECTOR' to enum types if missing.""" | ||
|
||
# Add to searchsourceconnectortype enum | ||
op.execute( | ||
""" | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_type t | ||
JOIN pg_enum e ON t.oid = e.enumtypid | ||
WHERE t.typname = 'searchsourceconnectortype' AND e.enumlabel = 'ZENDESK_CONNECTOR' | ||
) THEN | ||
ALTER TYPE searchsourceconnectortype ADD VALUE 'ZENDESK_CONNECTOR'; | ||
END IF; | ||
END | ||
$$; | ||
""" | ||
) | ||
|
||
# Add to documenttype enum | ||
op.execute( | ||
""" | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_type t | ||
JOIN pg_enum e ON t.oid = e.enumtypid | ||
WHERE t.typname = 'documenttype' AND e.enumlabel = 'ZENDESK_CONNECTOR' | ||
) THEN | ||
ALTER TYPE documenttype ADD VALUE 'ZENDESK_CONNECTOR'; | ||
END IF; | ||
END | ||
$$; | ||
""" | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
""" | ||
Downgrade logic not implemented since PostgreSQL | ||
does not support removing enum values. | ||
""" | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from datetime import datetime | ||
|
||
import httpx | ||
|
||
|
||
class ZendeskConnector: | ||
def __init__(self, subdomain: str, email: str, api_token: str): | ||
if not subdomain or not email or not api_token: | ||
raise ValueError("Subdomain, email, and API token cannot be empty.") | ||
self.base_url = f"https://{subdomain}.zendesk.com/api/v2" | ||
self.auth = (f"{email}/token", api_token) | ||
|
||
async def get_tickets( | ||
self, start_date: str | None = None, end_date: str | None = None | ||
): | ||
tickets = [] | ||
async with httpx.AsyncClient() as client: | ||
params = {} | ||
if start_date: | ||
# Zendesk API uses 'start_time' for filtering by updated_at | ||
# Convert YYYY-MM-DD to Unix timestamp | ||
start_timestamp = int( | ||
datetime.strptime(start_date, "%Y-%m-%d").timestamp() | ||
) | ||
params["start_time"] = start_timestamp | ||
|
||
url = f"{self.base_url}/tickets.json" | ||
while url: | ||
try: | ||
response = await client.get(url, auth=self.auth, params=params) | ||
response.raise_for_status() | ||
data = response.json() | ||
tickets.extend(data["tickets"]) | ||
url = data["next_page"] | ||
# Clear params for subsequent paginated requests as they are part of the next_page URL | ||
params = {} | ||
except httpx.HTTPStatusError as e: | ||
print( | ||
f"HTTP error occurred: {e.response.status_code} - {e.response.text}" | ||
) | ||
break | ||
except httpx.RequestError as e: | ||
print(f"An error occurred while requesting {e.request.url}: {e}") | ||
break | ||
return tickets | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.