xmppjs / hubot-xmpp

XMPP adapter for Hubot
180 stars 103 forks source link

Send HTML content when available #55

Closed Nevon closed 10 years ago

Nevon commented 10 years ago

XEP-0071 describes how to send XHTML over IM, and node-xmpp supports it already, so I would suggest the option to replace any image URL:s in the bot's replies with actual images.

An example would be:

<message>
  <body>Are you feeling down? Have a puppy: http://campuswellbeing.files.wordpress.com/2011/10/cute-puppies-with-worms.jpg
  </body>
  <html xmlns='http://jabber.org/protocol/xhtml-im'>
    <body xmlns='http://www.w3.org/1999/xhtml'>
      <p>Are you feeling down? Have a puppy: <img src='http://campuswellbeing.files.wordpress.com/2011/10/cute-puppies-with-worms.jpg'/></p>
    </body>
  </html>
</message>

The stuff in body is displayed if the receiving client doesn't support rich html content.

I'm not sure what the limitations are on what type of content you can embed (and what the clients can actually display), but I would even consider things like embedding youtube videos when someone sends a youtube link.

What do you think? I'm probably going to hack on it tomorrow, but as I'd rather not maintain my own fork in the long term, I'd like to hear if you're open to it. The features I'm suggesting would of course be strictly optional.

markstory commented 10 years ago

You can already do this kind of work in you scripts. If you send Xmpp.Element instances from your scripts they will be passed on. I'm not sure automatically swapping content out is wise as it could be a bit magical.

Nevon commented 10 years ago

I noticed that you could pass an Xmpp.Element through, but that would require script writers to be aware of what adapter is being used. You couldn't send an Xmpp.Element to a Twitter adapter. Hubot scripts should ideally work with any adapter, which is why I think this belongs on the adapter level, rather than in the scripting layer.

markstory commented 10 years ago

I'm not sure the magic is worth it. I know that some clients like adium will autolink images and urls without changes like this.

Nevon commented 10 years ago

You actually need a plugin for adium to do that, but yes, point taken. The clients themselves could take care of it (but most of them don't, since they support XEP-0071 instead).

I'm going to play around with it tomorrow regardless and see how it feels. If I like it, I'll create a pull request and you can have a look. If you don't dig it, reject it and I'll just try to maintain it as a fork.

farski commented 10 years ago

Adium linkifies URLs natively, as do most clients (Hangouts, etc). I would vote against this; I have no real desire for youtube embeds to start showing up in my clients even though they could probably support that functionality.

markstory commented 10 years ago

Detecting valid images is also error prone as there are many image urls that don't contain standard file extensions.

Nevon commented 10 years ago

Alright then, I'll close this and offload the responsibility to the receiving clients.

nickcaballero commented 9 years ago

I created a script to add similar functionality. It monitors messages sent by the bot that look like image URLs, and will use XEP-0231 to embed the image. I'm still working on it but it works as is: https://github.com/nickcaballero/hubot-xmpp-bob