agent: |
TKrLagwxRO9TnO1d3bpDAdd a Zendesk trigger for a keyword in a public ticket comment
Add a Zendesk trigger for a keyword in a public ticket comment
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
inputs
outputs
import requests
from requests.auth import HTTPBasicAuth
# Function to add a trigger to Zendesk
def add_zendesk_trigger(api_url, email, api_token, keyword, webhook_id):
headers = {
'Content-Type': 'application/json'
}
data_to_send = """
{
"id" : "{{ticket.id}}",
"subject" : "{{ticket.subject}}",
"latest_comment" : "{{ticket.latest_comment}}"
}
"""
data = {
'trigger': {
'title': f'Trigger for keyword {keyword}',
'conditions': {
'all': [
{
'field': 'comment_includes_word',
'operator': 'includes',
'value': keyword
},
{
'field': 'comment_is_public',
'value': True
}
]
},
'actions': [
{
'field': 'notification_webhook',
'value': [webhook_id, data_to_send]
}
]
}
}
basic_auth = HTTPBasicAuth(email + '/token', api_token)
response = requests.post(api_url, auth = basic_auth, headers=headers, json=data)
return response.status_code, response.json()
api_url = f'https://{subdomain}.zendesk.com/api/v2/triggers'
creds = _get_creds(zendesk_cred_label)['creds']
api_token = creds['password']
email = creds['username']
status_code, response_json = add_zendesk_trigger(api_url, email, api_token, keyword, webhook_id)
print(status_code)
print(json.dumps(response_json, indent=4))
copied