class zendeskHandler(filterHandler): """ Handler that creates zendeks tickets. Currently hardcoding filter rules (eg uri) but could make this configurabe if desired. May also break these filterHandlers out into their own file that users could create independently of the subscription setup here.... """ def __init__(self, infopath='~/files/zendeskinfo.yaml'): import yaml from zdesk import Zendesk with open(os.path.expanduser(infopath), 'rt') as f: self.zendeskinfo = yaml.load(f) self.zendesk = Zendesk(**self.zendeskinfo) def filter(self, message): if message['options']['action'] != 'create': print('Annotation was not a creation, run update path?') return data = message['payload'][0] if 'scicrunch.org' in data['uri']: return True def handler(self, message): data = message['payload'][0] exact = [ i['exact'] for o in data['target'] for i in o['selector'] if 'selector' in o and 'exact' in i ] exact = exact[0] if exact else 'No description provided' href = data['links']['incontext'] new_ticket = { 'ticket': { 'requester': { 'name': 'hypothesis bot', 'email': self.zendeskinfo['zdesk_email'], }, 'subject': 'hypothes.is annotation on {} by {}'.format( data['document']['title'], data['user'].split(':', 1)[1]), 'description': '"{}" | {} {}'.format(exact, data['text'], href), 'tags': data['tags'], #'ticket_field_entries': [ #{ #'ticket_field_id':24394906, # referrer #'value': 'hypothes.is {}'.format(data['user'].split(':',1)[1]) # hypothes.is #}, #{ #'ticket_field_id':24394926, # url #'ticket_field_id':'Url', # url #'value': data['links']['incontext'] # incontext_url #} #] } } result = self.zendesk.ticket_create(data=new_ticket) print(result)
def send_notification(self, subject, message, recipient=None): try: logger.info("Sending zendesk notification '%s'..." % subject) zendesk = Zendesk(self.auth_org_url, self.auth_email, self.auth_token, True) new_ticket = { 'ticket': { 'requester': { 'name': self.requester_name, 'email': self.requester_email, }, 'subject': subject, 'description': message, 'assignee_id': self.assignee_id } } zendesk.ticket_create(data=new_ticket) except Exception, e: logger.error("Error while sending zendesk notification:\n%s" % traceback.format_exc())
class zendeskHandler(filterHandler): """ Handler that creates zendeks tickets. Currently hardcoding filter rules (eg uri) but could make this configurabe if desired. May also break these filterHandlers out into their own file that users could create independently of the subscription setup here.... """ def __init__(self, infopath='~/files/zendeskinfo.yaml'): import yaml from zdesk import Zendesk with open(os.path.expanduser(infopath), 'rt') as f: self.zendeskinfo = yaml.load(f) self.zendesk = Zendesk(**self.zendeskinfo) def filter(self, message): if message['options']['action'] != 'create': print('Annotation was not a creation, run update path?') return data = message['payload'][0] if 'scicrunch.org' in data['uri']: return True def handler(self, message): data = message['payload'][0] exact = [i['exact'] for o in data['target'] for i in o['selector'] if 'selector' in o and 'exact' in i] exact = exact[0] if exact else 'No description provided' href = data['links']['incontext'] new_ticket = { 'ticket': { 'requester': { 'name': 'hypothesis bot', 'email': self.zendeskinfo['zdesk_email'], }, 'subject':'hypothes.is annotation on {} by {}'.format(data['document']['title'], data['user'].split(':',1)[1]), 'description': '"{}" | {} {}'.format(exact, data['text'], href) , 'tags': data['tags'], #'ticket_field_entries': [ #{ #'ticket_field_id':24394906, # referrer #'value': 'hypothes.is {}'.format(data['user'].split(':',1)[1]) # hypothes.is #}, #{ #'ticket_field_id':24394926, # url #'ticket_field_id':'Url', # url #'value': data['links']['incontext'] # incontext_url #} #] } } result = self.zendesk.ticket_create(data=new_ticket) print(result)
"name": "Request Origin", "raw_name": "Request Origin", "value": "Fixture Report", "default": False }, { "id": 360002362871, "name": "Root Cause (Marketing)", "raw_name": "Root Cause (Marketing)", "value": "N/A", "default": False }, { "id": 360002901632, "name": "Root Cause (Merchandising)", "raw_name": "Root Cause (Merchandising)", "value": str(dictionary[fcid].get('add_replace')).strip("{''}"), "default": False }] } } result = zendesk.ticket_create(data=new_ticket) print(result) pprint(new_ticket)
{ 'ticket_field_id': 1, 'value': 'venti' }, { 'ticket_field_id': 2, 'value': '$10' } ] } } # If a response results in returning a [location] header, then that # will be what is returned. # Create a ticket and get its URL. result = zendesk.ticket_create(data=new_ticket) # Alternatively, you can get the complete response and get the location # yourself. This can be useful for getting other response items that are # not normally returned, such as result['content']['upload']['token'] # when using zendesk.upload_create() # # result = zendesk.ticket_create(data=new_ticket, complete_response=True) # ticket_url = result['response']['location'] # ticket_id = get_id_from_url(ticket_url) # Need ticket ID? from zdesk import get_id_from_url ticket_id = get_id_from_url(result) # Show