Sign in
agent:

Trigger for tickets which have status new/open, group DevOps, assignee None, and public comment includes a keyword

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
import requests import json from requests.auth import HTTPBasicAuth creds = _get_creds(zendesk_cred_label)['creds'] api_token = creds['password'] email = creds['username'] # Replace the placeholder values with actual data group_name = 'DevOps' # Use the group name here keyword = 'forensics:' # Function to get group ID by name def get_group_id(subdomain, email, api_token, group_name): api_url = f'https://{subdomain}.zendesk.com/api/v2/groups.json' headers = { 'Content-Type': 'application/json' } basic_auth = HTTPBasicAuth(f'{email}/token', api_token) response = requests.get(api_url, auth=basic_auth, headers=headers) if response.status_code == 200: groups = response.json().get('groups', []) for group in groups: if group['name'].lower() == group_name.lower(): return group['id'] return None # Function to add a trigger to Zendesk def add_zendesk_trigger(subdomain, email, api_token, keyword, group_name, webhook_id): group_id = get_group_id(subdomain, email, api_token, group_name) if not group_id: return None, {"error": "Group not found"} api_url = f'https://{subdomain}.zendesk.com/api/v2/triggers' headers = { 'Content-Type': 'application/json' } data_to_send = json.dumps({ "id": "{{ticket.id}}", "subject": "{{ticket.subject}}", "requester": "{{ticket.requester.name}}", "requester_email": "{{ticket.requester.email}}", "description": "{{ticket.description}}", "status": "{{ticket.status}}", "priority": "{{ticket.priority}}", "assignee_id": "{{ticket.assignee_id}}", "tags": "{{ticket.tags}}", "created_at": "{{ticket.created_at}}", "updated_at": "{{ticket.updated_at}}", "comments": "{{ticket.comments_formatted}}" }) data = { 'trigger': { 'title': f'Trigger for keyword {keyword} in Group {group_name} avoiding trigger loop', 'conditions': { 'all': [ { 'field': 'group_id', 'operator': 'is', 'value': str(group_id) }, { 'field': 'comment_is_public', 'operator': 'is', 'value': 'true' }, { 'field': 'comment_includes_word', 'operator': 'is', 'value': keyword }, { 'field': 'current_tags', 'operator': 'not_includes', 'value': 'answered' } ], 'any': [ { 'field': 'status', 'operator': 'is', 'value': 'new' }, { 'field': 'status', 'operator': 'is', 'value': 'open' } ] }, 'actions': [ { 'field': 'notification_webhook', 'value': [webhook_id, data_to_send] } ] } } basic_auth = HTTPBasicAuth(f'{email}/token', api_token) response = requests.post(api_url, auth=basic_auth, headers=headers, json=data) return response.status_code, response.json() status_code, response_json = add_zendesk_trigger(subdomain, email, api_token, keyword, group_name, webhook_id) if status_code: print(status_code) print(json.dumps(response_json, indent=4)) else: print("Group not found or other error occurred")
copied