ocilo / skype-http

Unofficial Skype API for Node.js via HTTP
https://ocilo.github.io/skype-http
MIT License
51 stars 24 forks source link

Add support for image sending #47

Closed demurgos closed 6 years ago

demurgos commented 6 years ago

This commit adds the new sendMessage method to send an image. It requires the path for the image and the conversation ID.


This PR supersedes #46 by @Sorunome. I just fixed the few linting issues (missing types and line length) and squashed the commits.

James91 commented 6 years ago

If I wanted to send the image to a URL instead of path what would I have to do?

I get an {"error":"true","message":"ENOENT: no such file or directory, open 'https://www.ed.ac.uk/files/styles/panel_breakpoints_theme_uoe_mobile_1x/public/thumbnails/image/studying-postgraduate-degree-guide-online-learning-support.jpg?itok=7ZEdRfUv'"}

If I try to send an image? It works for a local path but I need an URL to send the image?

Also, if I was to display an image from get-messages what would I need to do?

Thanks, James

Sorunome commented 6 years ago

If I try to send an image? It works for a local path but I need an URL to send the image?

The way it is currently implemented you have to download the image first

Also, if I was to display an image from get-messages what would I need to do?

you basically check if the incoming event resource type is RichText/UriObject

James91 commented 6 years ago

you basically check if the incoming event resource type is RichText/UriObject

Could I get a bit more detail?

Thanks for the quick response 👍

mitchcapper commented 6 years ago

@James91 you might want to just dump the json to get a full idea of how incoming files look. That is the type for images and then original_file_name on the object you will want to look at.

Sorunome commented 6 years ago

Eeeeh, what i basically did is something like

skypeHttp.connect(opts).then(api => { 
  api.on("event", (ev) => {
    if (ev && ev.resource && ev.resource.type == "RichText/UriObject") {
      console.log(ev.resource); // you will find the remote image URL in here
    }
  });
});

That remote image URL will only work with the authorization context headers thingy and the cookies, which you can basically get like this:

// api is the same api as above, i saved it to some other variable
// cookies accessible via api.context.cookies
// skype token accessable via api.context.skypeToken.value
// so the "Authorization" header needs to be 'skype_token ' + api.context.skypeToken.value
James91 commented 6 years ago

Thank you :)

James91 commented 6 years ago

@Sorunome How should the headers be set out? Every attempt I make on postman / nodejs fails?

Sorunome commented 6 years ago

this is how i do it https://github.com/matrix-hacks/matrix-puppet-skype/blob/fb694ee542206e39c478d17702fbbb2070b73f9a/src/client.ts#L117-L124

where download.getBufferAndType is defined here: https://github.com/matrix-hacks/matrix-puppet-bridge/blob/be9f0f9c69b1d561f6cfb041264e93e355870f9f/src/utils.ts#L32-L43

James91 commented 6 years ago

Thanks - That resolved my issue :)