def update_snappy_ticket_with_extras(snappy_api, nonce, contact_key, subject): # Short-circuit if there are no extras if not settings.SNAPPY_EXTRAS: return True # Gets more extras from Vumi and creates a private note with them contacts_api = ContactsApiClient(auth_token=settings.VUMI_GO_API_TOKEN) contact = contacts_api.get_contact(contact_key) extra_info = "" for extra in settings.SNAPPY_EXTRAS: extra_info += extra + ": " + contact["extra"][extra] + "\n" if extra_info != "": # Send private note to_addr = [{ "name": "Internal Information", "address": settings.SNAPPY_EMAIL, }] snappy_api.create_note( mailbox_id=settings.SNAPPY_MAILBOX_ID, subject=subject, message=extra_info, to_addr=to_addr, id=nonce, scope="private", staff_id=settings.SNAPPY_STAFF_ID ) return True
def update_snappy_ticket_with_extras(snappy_api, nonce, contact_key, subject): # Short-circuit if there are no extras if not settings.SNAPPY_EXTRAS: return True # Gets more extras from Vumi and creates a private note with them contacts_api = ContactsApiClient(auth_token=settings.VUMI_GO_API_TOKEN) contact = contacts_api.get_contact(contact_key) extra_info = "" for extra in settings.SNAPPY_EXTRAS: extra_info += extra + ": " + contact["extra"][extra] + "\n" if extra_info != "": # Send private note to_addr = [{ "name": "Internal Information", "address": settings.SNAPPY_EMAIL, }] snappy_api.create_note(mailbox_id=settings.SNAPPY_MAILBOX_ID, subject=subject, message=extra_info, to_addr=to_addr, id=nonce, scope="private", staff_id=settings.SNAPPY_STAFF_ID) return True
def get_keys(items): keys = [] for item in items: key = item.get('key', None) if key is not None: keys.append(key) return keys with open(settings.PROCESSED_CONTACTS_FILENAME, 'r') as processed: for item in processed: item = json.loads(item) old_contacts = item.get('old_contacts') old_keys = get_keys(old_contacts) # Delete old contacts for key in old_keys: try: api.get_contact(key) logging.info('Fetched contact with key %s' % key) logging.debug('Contact: %s') except Exception as e: continue try: if DELETE_CONTACTS: api.delete_contact(key) except Exception as e: logging.warning('Error deleting contact') logging.debug('Contact key: %s' % key) logging.debug('Error: %s' % e.message)