/skype-web-api

An unofficial Skype API for JavaScript.

Primary LanguageJavaScriptMIT LicenseMIT

Skype API

Circle CI Status Coverage Status npm version code style: prettier jest

An unofficial Skype API for JavaScript.

Getting Started

Install with npm

$ npm i skype-web-api

Install with yarn

$ yarn add skype-web-api

Include the package

import SkypeWebApi from 'skype-web-api';

Usage

SkypeWebApi()

Initialize a new SkypeWebApi object with an empty session.

const skypeApi = new SkypeWebApi();

login(username: string, password: string): Tokens

Login with the Skype credentials of a user.

const tokens = skypeApi.login('SkypeUsernameOrEmail', 'SkypePassword');

This function returns a Tokens object defined as the following flow type:

type Tokens = {
  skypeToken: {
    value: string,
    epochMillisecondsExpiration: number,
  },
  registrationToken: {
    value: string,
    epochMillisecondsExpiration: number,
  },
};

Tokens are useful if you're working on a stateless application (e.g. website backend) and want to resume an existing session without requiring the user to login every time. To load a session from existing Tokens, refer to the constructor call below. Tokens are valid for 24 hours.

SkypeWebApi(tokens?: Tokens)

Loads an existing user session from a Tokens object (defined above).

const tokens = skypeApi.login('SkypeUsernameOrEmail', 'SkypePassword');
const skypeApi = new SkypeWebApi(tokens);

Tokens expire after 24 hours, after which the user has au authenticate again via the login() function.

getMyUserProfile(): UserProfile

Fetches the UserProfile of the currently logged-in user.

const myUserProfile = skypeApi.getMyUserProfile();

This function returns a user profile defined as the following flow type:

type UserProfile = {
  about: ?string,
  avatarUrl: ?string,
  birthday: ?string,
  city: ?string,
  countryCode: ?string
  emails: string[],
  firstName: ?string,
  lastName: ?string,
  gender: 'Unspecified' | 'Male' | 'Female',
  homePage: ?string,
  jobTitle: ?string,
  languageCode: ?string,
  mood: ?string,
  phoneHome: ?string,
  phoneMobile: ?string,
  phoneOffice: ?string,
  province: ?string,
  richMood: ?string,
  username: ?string,
  namespace: ?string,
};

getContacts(): Contact[]

Fetches all the currently logged-in user's contacts.

const contacts = skypeApi.getContacts();

This function returns a Contact defined as the following flow type:

type Contact = {
  profile: UserProfile,
  blocked: boolean,
  suggested: boolean,
  relationshipHistory: ?({
    type: string,
    subType: ?string,
    dateTime: string,
  }[]),
  displayName: string,
  mri: string,
};

getUserProfile(username: string): UserProfile

Fetches the full UserProfile of a contact from his username (possibly retrieved from an earlier getContacts() call).

const username = 'ContactUsername';
const userProfile = skypeApi.getUserProfile(username);

Like getMyUserProfile(), this function returns a single UserProfile.

getUserProfiles(usernames: string[]): UserProfile[]

Fetches the full UserProfile of many contacts instead of repeatedly calling getUserProfile().

const contactUsernames = [
  'Username1',
  'Username2',
  'Username3',
];
const contactProfiles = skypeApi.getUserProfiles(contactUsernames);

This function returns an array of UserProfile.

sendMessage(text: string, recipientMri: string)

Sends a message from the current user to one of his contact. recipientMri is the Windows Live ID of the contact with one of the following formats: <number>:live:<username or <number>:<email>. You can get the MRI of a contact with the getContacts() function.

skypeApi.sendMessage('Hello World', '8:live:bob');

sendFile(fileBuffer: Buffer, fileName: string, recipientMri: string): number

Sends a file from the current user to one of his contact. recipientMri is the Windows Live ID of the contact with one of the following formats: <number>:live:<username or <number>:<email>. You can get the MRI of a contact with the getContacts() function. Buffer is a standard Node.js buffer obtained by reading a file from the disk.

import fs from 'fs';
const buffer = fs.readFileSync('path/to/the/file');
skypeApi.sendFile(buffer, 'FileName.pdf', '8:live:bob');

The function returns the arrival timestamp of the file in milliseconds since epoch.

getMessages(contactMri: string): Message[]

Fetches the messages exchanged by the logged-in user and one of his contacts. contactMri is the Windows Live ID of the contact with one of the following formats: <number>:live:<username or <number>:<email>.

const messages = skypeApi.getMessages('8:live:bob');

The function returns an array of Message, defined by the following flow type:

type Message = {
  id: number,
  arrivalDateTime: string,
  composeDateTime: string,
  content: string,
  senderMri: string,
};