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

sending attachments / images? #12

Closed
dcsan opened this issue Jan 26, 2015 · 12 comments
Closed

sending attachments / images? #12

dcsan opened this issue Jan 26, 2015 · 12 comments

Comments

@dcsan
Copy link

dcsan commented Jan 26, 2015

the demo examples here just send a text response, vis:

+       response = text.split('').reverse().join('');
+       channel.send(response);
+       console.log('@%s responded with "%s"', slack.self.name, response);

can this node package be used to send other types of messages, or attachments?

I've tried sending JSON like:

 if (reply) {
        // channel.send(reply.string);
        msgpack = {
          type: "message",
          text: reply.string,
          icon_url: "http://laorquesta.mx/wp-content/uploads/2014/12/bikers-300x225.jpg",
          attachment: {
            "color": "#36a64f",
            "title": "drifter bot",
            "title_link": "http://superscriptjs.com/starter/quickstart"
          }
        }
        // channel.send(JSON.stringify(msgpack))
        channel.send(msgpack)

but just get an error back:

{ code: 2, msg: 'message text is missing' }
@evansolomon
Copy link
Contributor

Any argument to channel.send is treated as text.

Technically you could send binary data over the websocket, but I the library doesn't really support it and I imagine it wouldn't show up on the other end in a useful way.

@dcsan
Copy link
Author

dcsan commented Jan 27, 2015

so channel.sendtMessage should send attachments but i haven't been able to get that to work via the web API either. is there a working example/json anywhere? I couldn't find.

this is what i'm sending:

{ type: 'message',
  text: 'TEST MESSAGE',
  icon_url: 'http://lorempixel.com/48/48/',
  attachments: 
   [ { title: '*Title*',
       fallback: 'Title: testing *right now!*',
       text: 'Testing *right now!*',
       mrkdwn_in: [Object] } ],
  token: 'xoxp-2662813184-3515663524-3515664302-b8a82e',
  channel: 'C03F38ZCN' }
Ignoring... { id: 1,
  type: 'message',
  channel: 'C03F38ZCN',
  text: 'TEST MESSAGE' }

postMessage result: { ok: true, channel: 'C03F38ZCN', ts: '1422399323.000004' } 

and what i see:
image

is there a different type: 'message', ?

@evansolomon
Copy link
Contributor

Sorry, I don't quite understand the example here. Can you post more complete (ideally runnable) code?

@dcsan
Copy link
Author

dcsan commented Jan 27, 2015

here's the method which sends the JSON above.

slack._apiCall  

is a method in your lib.

function testAttachment(channel) {

  var att2 = {
    "title": "*Title*",
    "fallback": "Title: testing *right now!*",
    "text": "Testing *right now!*",

    "mrkdwn_in": ["text", "title", "fallback"]
  }

  msgpack = {
    type: "message",
    text: "TEST MESSAGE",
    icon_url: "http://lorempixel.com/48/48/",
    attachments: [att2]
  }

  msgpack.token = token
  msgpack.channel = channel.id

  console.log("msgpack", msgpack);
  slack._apiCall("chat.postMessage", msgpack, function(err, res){
    console.error("postMessage result:", err, res)
  })

}

@paulhammond
Copy link
Contributor

I think #15 (along with some changes to the server documented in slackapi/hubot-slack#148) will fix this? Can you confirm?

@podviaznikov
Copy link

I think I'm having the same problem.

I was able to send attachments before using Incoming Webhook functionality, but can't do it with Web API.

Should

{
    "fallback": "Required plain-text summary of the attachment.",

    "color": "#36a64f",

    "pretext": "Optional text that appears above the attachment block",

    "author_name": "Bobby Tables",
    "author_link": "http://flickr.com/bobby/",
    "author_icon": "http://flickr.com/icons/bobby.jpg",

    "title": "Slack API Documentation",
    "title_link": "https://api.slack.com/",

    "text": "Optional text that appears within the attachment",

    "fields": [
        {
            "title": "Priority",
            "value": "High",
            "short": false
        }
    ],

    "image_url": "http://my-website.com/path/to/image.jpg"
}

from https://api.slack.com/docs/attachments work with Web API?

@podviaznikov
Copy link

Does anyone know when this will be fixed? And slackapi/hubot-slack#148 to be merged.

@bobalazek
Copy link

Any news on this? Seems that it still doesn't work on the Web API.

@mmattax
Copy link

mmattax commented May 22, 2015

I ran into this as well. Attachments do not work when using the web api (though I'm not even using the node client, I'm making a raw curl request), switching to an incoming webhook made the attachments appear.

Something is broken at a lower level than the client. Hope it gets fixed.

@bobalazek
Copy link

I found out, what the problem was / is. You NEED to JSON encode the 'attachments' argument, so the 'attachments' is actually a string and not an object. Then it should work. At least for me that worked.

@jkresner
Copy link

@bobalazek stringifying worked thanks. Pretty peculiar solution :)

@ghost
Copy link

ghost commented Feb 14, 2016

The >= 2.0.0 release will now check this for you, so should be a little easier to use, you can see where it's doing that here

@ghost ghost closed this as completed Feb 14, 2016
aoberoi added a commit to aoberoi/node-slack-sdk that referenced this issue Mar 20, 2019
adds note about not being enterprise ready to the sample
This issue was closed.
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

No branches or pull requests

7 participants