Fixed an issue with comment history not copying correctly
This commit is contained in:
parent
70e3ed13b3
commit
e06b18f30d
@ -79,10 +79,7 @@ def checkRate(response):
|
|||||||
# Globals Variables
|
# Globals Variables
|
||||||
###################################
|
###################################
|
||||||
ticketArray = []
|
ticketArray = []
|
||||||
transArray = []
|
|
||||||
groupIdDefs_source = []
|
groupIdDefs_source = []
|
||||||
groupIdDefs_dest = []
|
|
||||||
contactIdDefs = []
|
|
||||||
sourceDom = ''
|
sourceDom = ''
|
||||||
destDom = ''
|
destDom = ''
|
||||||
sourceKey = ''
|
sourceKey = ''
|
||||||
@ -113,37 +110,37 @@ print('/_/ /_/\___/_/|_|\___/\__/ /_/ /_/ \__,_/_/ /_/____/_/ \___/_/
|
|||||||
print('=========================================================================')
|
print('=========================================================================')
|
||||||
|
|
||||||
## Getting transfer settings from user
|
## Getting transfer settings from user
|
||||||
sourceDom = input('Please enter the source domain:\n(ex. "https://your_domain.freshdesk.com")\n')
|
sourceDom = input('Please enter the source domain:\n(ex. "https://your_domain.freshdesk.com")\n> ')
|
||||||
if sourceDom == '':
|
if sourceDom == '':
|
||||||
print(f'{RED}Invalid Domain Provided{RESET}')
|
print(f'{RED}Invalid Domain Provided{RESET}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
clear(3)
|
clear(3)
|
||||||
sourceDom = "".join(sourceDom.split())
|
sourceDom = "".join(sourceDom.split())
|
||||||
print(f'SETTINGS:\nSource Domain: {GREEN}{sourceDom}{RESET}')
|
print(f'SETTINGS:\nSource Domain: {GREEN}{sourceDom}{RESET}\n=========================================================================')
|
||||||
sourceKey = input('Please provide the API Key for the source account:\n(Hint: You can find this from your profile settings menu in Freshdesk)\n')
|
sourceKey = input('Please provide the API Key for the source account:\n(Hint: You can find this from your profile settings menu in Freshdesk)\n> ')
|
||||||
if sourceKey == '':
|
if sourceKey == '':
|
||||||
print(f'{RED}Invalid Key Provided{RESET}')
|
print(f'{RED}Invalid Key Provided{RESET}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
clear(3)
|
clear(3)
|
||||||
sourceKey = "".join(sourceKey.split())
|
sourceKey = "".join(sourceKey.split())
|
||||||
destDom = input('Please enter the destination domain:\n')
|
destDom = input('Please enter the destination domain:\n> ')
|
||||||
if destDom == '':
|
if destDom == '':
|
||||||
print(f'{RED}Invalid Domain Provided{RESET}')
|
print(f'{RED}Invalid Domain Provided{RESET}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
clear(4)
|
clear(4)
|
||||||
destDom = "".join(destDom.split())
|
destDom = "".join(destDom.split())
|
||||||
print(f'Source Domain: {GREEN}{sourceDom}{RESET} || Target Domain: {GREEN}{destDom}{RESET}')
|
print(f'Source Domain: {GREEN}{sourceDom}{RESET}\nDestination Domain: {GREEN}{destDom}{RESET}\n=========================================================================')
|
||||||
destKey = input('Please provide the API key for the destination account:\n')
|
destKey = input('Please provide the API key for the destination account:\n> ')
|
||||||
if destKey == '':
|
if destKey == '':
|
||||||
print(f'{RED}Invalid Key Provided{RESET}')
|
print(f'{RED}Invalid Key Provided{RESET}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
clear(3)
|
clear(2)
|
||||||
destKey = "".join(destKey.split())
|
destKey = "".join(destKey.split())
|
||||||
targetGroup = input('What is the name of the Freshdesk group you want to transfer from?\n')
|
targetGroup = input('What is the name of the Freshdesk group you want to transfer from?\n> ')
|
||||||
if targetGroup == '':
|
if targetGroup == '':
|
||||||
print(f'{RED}Invalid Group Name Provided{RESET}')
|
print(f'{RED}Invalid Group Name Provided{RESET}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -158,14 +155,11 @@ print(f'Obtaining account information...◐')
|
|||||||
groupIdDefs_source = makeCall(sourceDom + '/api/v2/groups', 'get', sourceKey)
|
groupIdDefs_source = makeCall(sourceDom + '/api/v2/groups', 'get', sourceKey)
|
||||||
clear(1)
|
clear(1)
|
||||||
print(f'Obtaining account information...◓')
|
print(f'Obtaining account information...◓')
|
||||||
contactIdDefs = makeCall(sourceDom + '/api/v2/contacts', 'get', sourceKey)
|
|
||||||
clear(1)
|
|
||||||
print(f'Obtaining account information...◑')
|
|
||||||
groupIdDefs_dest = makeCall(destDom + '/api/v2/groups', 'get', destKey)
|
groupIdDefs_dest = makeCall(destDom + '/api/v2/groups', 'get', destKey)
|
||||||
clear(1)
|
clear(1)
|
||||||
print(f'Obtaining account information...◒')
|
print(f'Obtaining account information...◑')
|
||||||
for i, group in enumerate(groupIdDefs_source):
|
for i, group in enumerate(groupIdDefs_source):
|
||||||
anim = ['◐', '◓', '◑', '◒']
|
anim = ['◒','◐', '◓', '◑']
|
||||||
if group["name"] == targetGroup:
|
if group["name"] == targetGroup:
|
||||||
targetGroupId = group["id"]
|
targetGroupId = group["id"]
|
||||||
break
|
break
|
||||||
@ -176,24 +170,26 @@ print(f'Obtaining account information...{GREEN}COMPLETE{RESET}')
|
|||||||
|
|
||||||
## Building Ticket Array from Source
|
## Building Ticket Array from Source
|
||||||
print(f'Gathering list of tickets from source...')
|
print(f'Gathering list of tickets from source...')
|
||||||
ticketArray = makeCall(sourceDom + '/api/v2/search/tickets?query=' + urllib.parse.urlencode(f'"group_id:\'{targetGroupId}\'"'), 'get', sourceKey)
|
#ticketArray = makeCall(sourceDom + '/api/v2/search/tickets?query=' + urllib.parse.urlencode(f'"group_id:\'{targetGroupId}\'"'), 'get', sourceKey)
|
||||||
|
ticketArray = makeCall(f'{sourceDom}/api/v2/search/tickets?query="group_id:{targetGroupId}"', 'get', sourceKey)
|
||||||
clear(1)
|
clear(1)
|
||||||
print(f'Gathering list of tickets from source...{GREEN}COMPLETE{RESET}')
|
print(f'Gathering list of tickets from source...{GREEN}COMPLETE{RESET}')
|
||||||
|
|
||||||
## Transferring tickets to Destination
|
## Transferring tickets to Destination
|
||||||
print(f'*This may take a while*')
|
print(f'{YELLOW}*This may take a while*{RESET}')
|
||||||
print(f'Transferring tickets to destination account...◐')
|
print(f'Transferring tickets to destination account...◐')
|
||||||
for i, ticket in enumerate(ticketArray):
|
for i, ticket in enumerate(ticketArray['results']):
|
||||||
attachments = {}
|
attachments = {}
|
||||||
anim = ['◓', '◑', '◒', '◐']
|
anim = ['◓', '◑', '◒', '◐']
|
||||||
ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey)
|
ticketData = makeCall(sourceDom + f'/api/v2/tickets/{ticket["id"]}?include=conversations,requester', 'get', sourceKey)
|
||||||
for x, attachment in enumerate(ticket['attachments']):
|
if 'attachments' in ticket:
|
||||||
if attachment['attachment_url']:
|
for x, attachment in enumerate(ticket['attachments']):
|
||||||
fileRes = requests.get(attachment.attachment_url)
|
if attachment.get('attachment_url'):
|
||||||
if fileRes.status_code == 200:
|
fileRes = requests.get(attachment.attachment_url)
|
||||||
attachments[x] = (attachment['name'], fileRes.content)
|
if fileRes.status_code == 200:
|
||||||
else:
|
attachments[x] = (attachment['name'], fileRes.content)
|
||||||
print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}')
|
else:
|
||||||
|
print(f'{RED}File Error:{RESET}\nFailed to download {attachment["name"]}')
|
||||||
payload = {
|
payload = {
|
||||||
'name': ticketData["requester"]["name"],
|
'name': ticketData["requester"]["name"],
|
||||||
'email': ticketData["requester"]["email"],
|
'email': ticketData["requester"]["email"],
|
||||||
@ -204,7 +200,7 @@ for i, ticket in enumerate(ticketArray):
|
|||||||
'description': ticketData["description"],
|
'description': ticketData["description"],
|
||||||
'source': ticketData["source"],
|
'source': ticketData["source"],
|
||||||
}
|
}
|
||||||
makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, files=attachments if attachments else None)
|
newTicket = makeCall(destDom + '/api/v2/tickets', 'post', destKey, payload, files=attachments if attachments else None)
|
||||||
|
|
||||||
## Gaterhing conversation history from ticketData, and then updating the ticket to include them in a private note
|
## Gaterhing conversation history from ticketData, and then updating the ticket to include them in a private note
|
||||||
if len(ticketData['conversations']) > 0:
|
if len(ticketData['conversations']) > 0:
|
||||||
@ -214,20 +210,23 @@ for i, ticket in enumerate(ticketArray):
|
|||||||
=====================<br>
|
=====================<br>
|
||||||
'''
|
'''
|
||||||
for convo in ticketData['conversations']:
|
for convo in ticketData['conversations']:
|
||||||
for contact in contactIdDefs:
|
if convo['incoming'] == False:
|
||||||
if contact['id'] == convo['user_id']:
|
agent = (makeCall(sourceDom + f'/api/v2/agents/{convo["user_id"]}', 'get', sourceKey))
|
||||||
username = contact['name']
|
username = agent["contact"]["name"]
|
||||||
break
|
if convo['incoming'] == True:
|
||||||
if convo['private'] == 'true':
|
user = (makeCall(sourceDom + f'/api/v2/contacts/{convo["user_id"]}', 'get', sourceKey))
|
||||||
convos += f'Private Note from {username}:<br>{convo["body"]}<br>---------------------------<br><br>'
|
username = user["name"]
|
||||||
elif convo['private'] == 'false' and convo['incoming'] == 'true':
|
if convo['private'] == True:
|
||||||
convos += f'Incoming Reply from {username}:<br>{convo["body"]}<br>---------------------------<br><br>'
|
convos += f'<b>Private Note from {username}:</b><br>{convo["body"]}<br>---------------------------<br>'
|
||||||
elif convo['private'] == 'false' and convo['incoming'] == 'false':
|
elif convo['private'] == False and convo['incoming'] == True:
|
||||||
convos += f'Outgoing Reply from {username}:<br>{convo["body"]}<br>---------------------------<br><br>'
|
convos += f'<b>Incoming Reply from {username}:</b><br>{convo["body"]}<br>---------------------------<br>'
|
||||||
makeCall(destDom + f'/api/v2/tickets/{ticket['id']}/notes', 'post', destKey,{'body': convos})
|
elif convo['private'] == False and convo['incoming'] == False:
|
||||||
|
convos += f'<b>Outgoing Reply from {username}:</b><br>{convo["body"]}<br>---------------------------<br>'
|
||||||
|
makeCall(destDom + f'/api/v2/tickets/{newTicket["id"]}/notes', 'post', destKey,{'body': convos})
|
||||||
|
|
||||||
clear(1)
|
clear(1)
|
||||||
print(f'Transferring tickets to destination account...{anim[i % len(anim)]}')
|
print(f'Transferring tickets to destination account...{anim[i % len(anim)]}')
|
||||||
|
i += 1
|
||||||
clear(2)
|
clear(2)
|
||||||
print(f'Transferring tickets to destination account...{GREEN}COMPLETE{RESET}')
|
print(f'Transferring tickets to destination account...{GREEN}COMPLETE{RESET}')
|
||||||
print(f'{GREEN}*TICKET TRANSFER COMPLETED SUCCESSFULLY*{RESET}')
|
print(f'{GREEN}*TICKET TRANSFER COMPLETED SUCCESSFULLY*{RESET}')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user