Hubot-slack: File Upload Documentation

Created on 25 Oct 2017  路  4Comments  路  Source: slackapi/hubot-slack

Description

I'm looking for documentation for how to upload a file. I see that support was added in v4.0.0 for uploading files, but am unsure how to use this feature.

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.
question

Most helpful comment

@sergioagg Here's a full sample script for you. This listens for a message of 'testslackfileupload' followed by the name of the file you want to send to slack. You can obviously set the file name within the script rather than passing it in through the message if you want.

# Description:
#   contains listener that will upload file to slack
#
# Commands:
#   hubot testslackfileupload <filename> - uploads file to slack with the filename passed in
#
# Author:
#   juilianoj

module.exports = (robot) -> 
    robot.respond /testslackfileupload (.*)/i, (res) ->
        filename = res.match[1]

        opts = {
            content: 'the content of your file'
            title: 'Your Test File Title As Displayed In Slack'
            channels: res.message.room
        }
        robot.adapter.client.web.files.upload(filename, opts)

The result looks like this, and when you download the file it would have the file name you passed in:

image

All 4 comments

I realized that I must contact the robot.adapter.client.web.files.upload method. Ticket can be closed.

Example:

opts = { content: body channels: res.message.room } robot.adapter.client.web.files.upload('filename.ext', opts)

@juilianoj can you please post a example of your full request to upload the file? I'm stuck trying to do the same.

@sergioagg Here's a full sample script for you. This listens for a message of 'testslackfileupload' followed by the name of the file you want to send to slack. You can obviously set the file name within the script rather than passing it in through the message if you want.

# Description:
#   contains listener that will upload file to slack
#
# Commands:
#   hubot testslackfileupload <filename> - uploads file to slack with the filename passed in
#
# Author:
#   juilianoj

module.exports = (robot) -> 
    robot.respond /testslackfileupload (.*)/i, (res) ->
        filename = res.match[1]

        opts = {
            content: 'the content of your file'
            title: 'Your Test File Title As Displayed In Slack'
            channels: res.message.room
        }
        robot.adapter.client.web.files.upload(filename, opts)

The result looks like this, and when you download the file it would have the file name you passed in:

image

@juilianoj awesome! that's exactly what I was looking for, really appreciated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EasyAsABC123 picture EasyAsABC123  路  13Comments

magander3 picture magander3  路  8Comments

jabbink picture jabbink  路  4Comments

DonEmil picture DonEmil  路  9Comments

ojacques picture ojacques  路  9Comments