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

How to interact with group chats? #81

Open AidanLovelace opened 6 years ago

AidanLovelace commented 6 years ago

Is there a way to interact with group chats? (Not the old p2p. The new ones. Like that random one I created 2 days ago.)

demurgos commented 6 years ago

You can send messages to group chats just as you send messages to simple contacts. Instead of using the contact id, use the group chat id (a string starting with 19:).

You can get events from group chats and respond to them but the API to list the group chats you are participating in is missing at the moment.

const onMessage = (resource: resources.TextResource): void => {
  const conversationId: string = resource.conversation;
  // This is the id of the simple contact or group chat
  console.log(conversationId);
  // There was a recent update to help to handle resources by id:
  // import * as mri from "skype-http/mri"
  // if (mri.parse(conversationId).type === mri.MriType.GroupConversation) {
  //  console.log("This is a group conversation");
  // }
  api.sendMessage({textContent: "Hello, World!"}, conversationId).catch(console.error);
};

api.on("Text", onMessage);
api.on("RichText", onMessage);
demurgos commented 6 years ago

I haven't looked into it but if you find the API endpoint to list the currently existing group chats, it would be a nice addition.

demurgos commented 6 years ago
https://client-s.gateway.messenger.live.com/v1/users/ME/conversations?startTime=1514877701928&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread|PSTN

The method above lists the available conversations: PMs and group chats. I'll try to add support for this as soon as possible. You can then use sendMessage with the id of the conversation to send messages to group chats.

demurgos commented 6 years ago

Huh, well. It turns out that the method to get the conversations already exists 😄 : https://github.com/ocilo/skype-http/blob/faf48795e7cbb041cf337cbe5ee8e98bfc414187/src/lib/api.ts#L69

Still, I'll update the types to match the contacts API.

demurgos commented 6 years ago

Updating the conversation types also requires me to update the message types. It will improve the health of the lib a lot but requires more time. I started work on my repo. I'll probably finish it next week.