Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttachmentsFormatter function #2

Closed
FredericLatour opened this issue Oct 24, 2018 · 2 comments · Fixed by #3
Closed

AttachmentsFormatter function #2

FredericLatour opened this issue Oct 24, 2018 · 2 comments · Fixed by #3

Comments

@FredericLatour
Copy link

What do you think of allowing for an attachment formatter function?
The reason is that having meta information formatted as an attachment is not necessarily great for other transports (file, console, etc ...).
By having an attachmentFormatter (or transformer whatever name you prefer) function, it would be possible to convert the generic meta information into attachment just for slack.

    if (this.attachmentFormatter && typeof this.attachmentFormatter === 'function') {
      payload.attachments = this.attachmentFormatter(info)
    } else {
      // for compatibility with the way it currently works
      let attachments = []
      let attachmentKeys = Object.keys(info).filter(key => !isNaN(parseInt(key)))
      attachmentKeys.forEach(key => attachments.push(info[key]))
      payload.attachments = attachments
    }
@TheAppleFreak
Copy link
Owner

That sounds like a good idea! This was an issue that I was mulling pretty recently, actually, but it never crossed my mind to use something like a formatter function. I'll integrate that when I get a chance.

@TheAppleFreak
Copy link
Owner

Well, it took a bit for me to remember to do this, but that's now been implemented! It's a breaking change, but it's for the best in the long term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants