Zendesk > Jira: Attachments.created missing?

Originally asked by Hannu Turunen on 15 March 2021 (original question)


Hi.

I’m trying to merge last/latest comment & all the attachments on that comment from ZD to JIRA. For that I think I need the attachment created timestamp so I can compare that to comment timestamp.

Or is there a better way to catch all the attachments of a single comment?

Looking at JIRA remote replica, I can’t find attachment created timestamp.

According to https://docs.idalko.com/exalate/display/ED/Attachments should there be a timestamp?

Here’s the JIRA remote replica attachments & comments from ZD:

{
“version”: {
“major”: 1,
“minor”: 15,
“patch”: 0
},

“hubIssue”: {
“components”: ,
attachments”: [
{
“id”: “369197845598”,
“mimetype”: “image/png”,
“filename”: “inline-453156139.png”,
“filesize”: 927,
“internal”: false,
“zip”: false
},
{
“id”: “369242875237”,
“mimetype”: “image/png”,
“filename”: “image.png”,
“filesize”: 4009,
“internal”: true,
“zip”: false
},
{
“id”: “369242886377”,
“mimetype”: “text/plain”,
“filename”: “test.txt”,
“filesize”: 58080,
“internal”: true,
“zip”: false
},
{
“id”: “369197873058”,
“mimetype”: “image/png”,
“filename”: “image.png”,
“filesize”: 1762,
“internal”: true,
“zip”: false
}
],

“description”: “test”,
“watchers”: ,
“fixVersions”: ,
“key”: “860”,
“summary”: “testing 4.5”,
comments”: [
{
“id”: “782263108038”,
“author”: {
“key”: “398349362114”,
“active”: false,
“email”: “xxx”,
“displayName”: “xxx”,
“username”: “xxx”
},
“body”: “xxx”,
“created”: 1614775537000,
“internal”: true,
“restrictSync”: false
},
{
“id”: “782263552298”,
“author”: {
“key”: “398349362114”,
“active”: false,
“email”: “xxx”,
“displayName”: “xxx”,
“username”: “xxx”
},
“body”: “xxx2”,
“created”: 1614775574000,
“internal”: true,
“restrictSync”: false
}
],


Comments:

Francis Martens (Exalate) commented on 16 March 2021

It is a bit unclear what exactly you would like to achieve.
Send over all the attachments contained in a comment?

Hannu Turunen commented on 16 March 2021

Hi.

Yes, just the latest comment and all the attachments contained on it.

ZD agents might do internal commenting/notes before escalating to JIRA and we don’t want those comments & attachments to JIRA. Just the last comment & all the attachements on that comment.

I can successfully take the last comment and last attachment but if the last comment contains 2+ attachments, I can’t tell which attachment is linked to last comment.

Francis Martens (Exalate) commented on 26 March 2021

An approach would be to scan the last comment for attachments and add these attachments to the replica?

Answer by Francis Martens (Exalate) on 22 May 2021

Hannu Turunen

Found some time to work on this one.
Following snippet will add to the replica only the attachments which are mentioned in a comment

Outgoing Sync | Zendesk side

// commentFiles is used to collect all the filenames mentioned in comments
//

def commentFiles = []

issue.comments.each { 
    comment ->

    // the regexp is used to fetch the name of a file mentioned in a zendesk ticket comment
    // THis is something like 
    // ![](https://d3v-peter.zendesk.com/attachments/token/EfCbLqeb9gmdox1IS4PFL20Yh/?name=AzureDevOps-Jira.png)
    def matcher = comment.body =~ /!\[\]\(\S+?name=(\S+)\)/
    matcher.each {
        commentFiles.add(it[1])
    }
}

// only send the attachments which have been mentioned in a comment
replica.attachments = issue.attachments.findAll { commentFiles.contains(it.filename) }




The snippet can also be found here.
It should be self explanatory