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

New errors #1

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var skypeHttp = require("skype-http");

## Quick start

The code below sends `Hello, World!` to all of `bob`'s contacts.
The code below sends `Hello, World!` to all of `bob`'s contacts. If bob's skype account was an MSA account(rather than older skype login) he would login with "bob@bobsdomain.com".

```typescript
import { Api, connect } from "skype-http";
Expand All @@ -52,8 +52,7 @@ run();

## Running example

The demo will prompt you your username and password: you should use your Skype account (there is no support for
Microsoft accounts for now).
The demo will prompt you your username and password: you should use your Skype account or MSA.

````shell
git clone https://github.com/demurgos/skype-http
Expand Down
10,991 changes: 6,439 additions & 4,552 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,39 @@
"dependencies": {
"@types/cheerio": "^0.22.7",
"@types/form-data": "^2.2.1",
"@types/gulp": "^4.0.6",
"@types/lodash": "^4.14.102",
"@types/request": "^2.47.0",
"@types/tough-cookie": "^2.3.2",
"async-file": "^2.0.2",
"big-integer": "^1.6.26",
"bluebird": "^3.5.1",
"cheerio": "^1.0.0-rc.2",
"incident": "^3.1.1",
"cheerio": "^1.0.0-rc.3",
"incident": "^3.2.0",
"js-sha256": "^0.9.0",
"kryo": "^0.6.1",
"lodash": "^4.17.5",
"request": "^2.83.0",
"tough-cookie": "^2.3.3"
"kryo": "^0.8.1",
"lodash": "^4.17.11",
"request": "^2.88.0",
"tough-cookie": "^2.4.3"
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/chai": "^4.1.7",
"@types/minimist": "^1.2.0",
"@types/mocha": "^2.2.48",
"@types/node": "^9.4.6",
"chai": "^4.1.2",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.10",
"chai": "^4.2.0",
"del": "^3.0.0",
"fs-extra": "^5.0.0",
"glob": "^7.1.2",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"gulp": "^4.0.0",
"gulp-cli": "^2.0.1",
"minimist": "^1.2.0",
"mocha": "^5.0.1",
"mocha": "^5.2.0",
"pre-commit": "^1.2.2",
"ts-node": "^4.1.0",
"tslint": "^5.9.1",
"turbo-gulp": "^0.16.2",
"typescript": "2.7.0-rc"
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"turbo-gulp": "^0.17.1",
"typescript": "^3.4.5"
},
"nyc": {
"include": [
Expand Down
21 changes: 21 additions & 0 deletions src/example/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ async function runExample(): Promise<void> {
await api.listen();
await api.setStatus("Online");
console.log("Ready");

// Check if the Skype Bot, and Skype Echo are already added as contacts
console.log("Adding Skype bot as contact");
const skypeTranslatorBot: string = "0d5d6cff-595d-49d7-9cf8-973173f5233b";
const addBot: boolean = await api.addBotToContact(skypeTranslatorBot);
if (addBot) {
console.log("Removing Skype bot from contacts");
await api.removeBotFromContacts(skypeTranslatorBot);
}

console.log("Adding Skype Echo as contact");
const echoSoundTest: string = "8:echo123";
const wasContactAdded: boolean = await api.addUserAsContact(echoSoundTest);
if (wasContactAdded) {
console.log("Removing Skype Echo from contacts");
await api.removeUserFromContacts(echoSoundTest);
}

console.log("Searching Skype directory");
const searchResults: String = await api.searchSkypeDirectory("testing");
console.log(searchResults);
}

runExample()
Expand Down
Binary file added src/lib/.DS_Store
Binary file not shown.
26 changes: 24 additions & 2 deletions src/lib/api-uri.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import url from "url";
import { SKYPEWEB_API_SKYPE_HOST } from "./consts";
import { SKYPEWEB_API_SKYPE_HOST, SKYPEWEB_CONTACTS_HOST } from "./consts";

export const DEFAULT_USER: string = "self";

Expand Down Expand Up @@ -29,11 +29,21 @@ function buildContacts(username: string): string[] {
return buildUser(username).concat("contacts");
}

// /users/:user/invites
function buildInvites(username: string): string[] {
return buildUser(username).concat("invites");
}

// /users/:user/contacts/auth-request/:contact
function buildAuthRequest(username: string, contact: string): string[] {
return buildContacts(username).concat("auth-request", contact);
}

// /users/:user/invites/:contact
function buildInviteRequest(username: string, contact: string): string[] {
return buildInvites(username).concat(contact);
}

// /users/:user/contacts/auth-request/:contact/accept
function buildAuthRequestAccept(username: string, contact: string): string[] {
return buildAuthRequest(username, contact).concat("accept");
Expand All @@ -44,6 +54,10 @@ function buildAuthRequestDecline(username: string, contact: string): string[] {
return buildAuthRequest(username, contact).concat("decline");
}

function buildInviteRequestAccept(username: string, contact: string): string[] {
return buildInviteRequest(username, contact).concat("accept");
}

// /users/:user/displayname
function buildDisplayName(username: string): string[] {
return buildUser(username).concat("displayname");
Expand Down Expand Up @@ -95,10 +109,18 @@ function getOrigin(): string {
return "https://" + SKYPEWEB_API_SKYPE_HOST;
}

function getContact(): string {
return `https://${SKYPEWEB_CONTACTS_HOST}`;
}

function get(p: string) {
return url.resolve(getOrigin(), p);
}

function getC(p: string) {
return url.resolve(getContact(), p);
}

export function displayName(username: string): string {
return get(joinPath(buildDisplayName(username)));
}
Expand All @@ -112,7 +134,7 @@ export function userProfiles(): string {
}

export function authRequestAccept(username: string, contact: string): string {
return get(joinPath(buildAuthRequestAccept(username, contact)));
return getC(joinPath(buildInviteRequestAccept(username, contact)));
}

export function authRequestDecline(username: string, contact: string): string {
Expand Down
35 changes: 34 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import events from "events";
import { acceptContactRequest } from "./api/accept-contact-request";
import { addBotAsContact, removeBotFromContacts } from "./api/add-bot-as-contact";
import { addMemberToConversation } from "./api/add-member";
import { addUserAsContact, removeUserFromContacts } from "./api/add-user-as-contact";
import { createConversation } from "./api/create-conversation";
import { declineContactRequest } from "./api/decline-contact-request";
import { getContact } from "./api/get-contact";
import { getConversation } from "./api/get-conversation";
import { getConversations } from "./api/get-conversations";
import { getJoinUrl } from "./api/get-join-url";
import { searchSkypeDirectory } from "./api/search-directory";
import { sendAudio } from "./api/send-audio";
import { sendDocument } from "./api/send-document";
import { sendImage } from "./api/send-image";
import { sendMessage } from "./api/send-message";
import { setConversationTopic } from "./api/set-conversation-topic";
Expand Down Expand Up @@ -59,10 +64,30 @@ export class Api extends events.EventEmitter implements ApiEvents {
return this.contactsService.getInvites(this.context);
}

async searchSkypeDirectory(contactId: string): Promise<String> {
return searchSkypeDirectory(this.io, this.context, contactId);
}

async getContact(contactId: string): Promise<_Contact> {
return getContact(this.io, this.context, contactId);
}

async addBotToContact(contactId: string): Promise<boolean> {
return addBotAsContact(this.io, this.context, contactId);
}

async removeBotFromContacts(contactId: string): Promise<boolean> {
return removeBotFromContacts(this.io, this.context, contactId);
}

async addUserAsContact(contactId: string): Promise<boolean> {
return addUserAsContact(this.io, this.context, contactId);
}

async removeUserFromContacts(contactId: string): Promise<boolean> {
return removeUserFromContacts(this.io, this.context, contactId);
}

async getContacts(): Promise<Contact[]> {
return this.contactsService.getContacts(this.context);
}
Expand All @@ -79,6 +104,10 @@ export class Api extends events.EventEmitter implements ApiEvents {
return sendMessage(this.io, this.context, message, conversationId);
}

async sendDocument(message: api.NewDocument, conversationId: string): Promise<api.SendMessageResult> {
return sendDocument(this.io, this.context, message, conversationId);
}

async setConversationTopic(conversationId: string, topic: string): Promise<void> {
return setConversationTopic(this.io, this.context, conversationId, topic);
}
Expand All @@ -95,7 +124,11 @@ export class Api extends events.EventEmitter implements ApiEvents {
return createConversation(this.io, this.context, allUsers);
}

async sendImage(message: api.NewImage, conversationId: string): Promise<api.SendMessageResult> {
async sendAudio(message: api.NewMediaMessage, conversationId: string): Promise<api.SendMessageResult> {
return sendAudio(this.io, this.context, message, conversationId);
}

async sendImage(message: api.NewMediaMessage, conversationId: string): Promise<api.SendMessageResult> {
return sendImage(this.io, this.context, message, conversationId);
}

Expand Down
5 changes: 3 additions & 2 deletions src/lib/api/accept-contact-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { Context } from "../interfaces/api/context";
import * as io from "../interfaces/http-io";

export async function acceptContactRequest(io: io.HttpIo, apiContext: Context, contactUsername: string): Promise<void> {
const requestOptions: io.GetOptions = {
const requestOptions: io.PutOptions = {
uri: apiUri.authRequestAccept(apiContext.username, contactUsername),
cookies: apiContext.cookies,
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.put(requestOptions);
if (res.statusCode !== 201) {
if (res.statusCode !== 200) {
return Promise.reject(new Incident("net", "Failed to accept contact"));
}
}
42 changes: 42 additions & 0 deletions src/lib/api/add-bot-as-contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Context } from "../interfaces/api/context";
import * as io from "../interfaces/http-io";

export async function addBotAsContact(io: io.HttpIo,
apiContext: Context,
botId: string): Promise<boolean> {
const requestOptions: io.PutOptions = {
uri: `https://api.aps.skype.com/v1/relationship/me/${botId}`,
cookies: apiContext.cookies,
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.put(requestOptions);

if (res.statusCode !== 204) {
console.log(`Unable to add BOT ${botId} as contact.
Res Body:${res.body} Res Code: ${res.statusCode}`);
}
return res.statusCode === 204;
}

export async function removeBotFromContacts(io: io.HttpIo,
apiContext: Context,
botId: string): Promise<boolean> {
const requestOptions: io.DeleteOptions = {
uri: `https://api.aps.skype.com/v1/relationship/me/${botId}`,
cookies: apiContext.cookies,
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.del(requestOptions);

if (res.statusCode !== 204) {
console.log(`Unable to remove BOT ${botId} from contacts.
Res Body:${res.body} Res Code: ${res.statusCode}`);
}
return res.statusCode === 204;
}
1 change: 1 addition & 0 deletions src/lib/api/add-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function addMemberToConversation(
"RegistrationToken": apiContext.registrationToken.raw,
"Content-type": "application/json",
},
proxy: apiContext.proxy,
};

const res: io.Response = await io.put(requestOptions);
Expand Down
63 changes: 63 additions & 0 deletions src/lib/api/add-user-as-contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Context } from "../interfaces/api/context";
import * as io from "../interfaces/http-io";

interface RequestBody {
value: boolean;
}

/*
In order to use this feature you need to first identify the user's skype id, as seen by skype
EX: 8:live:new_user or 8:old_user
*/

export async function addUserAsContact(io: io.HttpIo,
apiContext: Context,
userId: string): Promise<boolean> {
const requestBody: RequestBody = {
value: true,
};

const requestOptions: io.PutOptions = {
uri: `https://edge.skype.com/pcs-df/contacts/v2/users/${encodeURIComponent(apiContext.username)
}/contacts/${encodeURIComponent(userId)}/explicit`,
cookies: apiContext.cookies,
body: JSON.stringify(requestBody),
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.put(requestOptions);

if (res.statusCode !== 200) {
console.log(`Unable to add USER ${userId} as contact.
Res Body:${res.body} Res Code: ${res.statusCode}`);
}
return res.statusCode === 200;
}

export async function removeUserFromContacts(io: io.HttpIo,
apiContext: Context,
userId: string): Promise<boolean> {
const requestBody: RequestBody = {
value: false,
};
const requestOptions: io.PutOptions = {
uri: `https://edge.skype.com/pcs-df/contacts/v2/users/${encodeURIComponent(apiContext.username)
}/contacts/${encodeURIComponent(userId)}/explicit`,

cookies: apiContext.cookies,
body: JSON.stringify(requestBody),
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.put(requestOptions);

if (res.statusCode !== 200) {
console.log(`Unable to remove USER ${userId} from contacts.
Res Body:${res.body} Res Code: ${res.statusCode}`);
}
return res.statusCode === 200;
}
1 change: 1 addition & 0 deletions src/lib/api/create-conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function createConversation(
RegistrationToken: apiContext.registrationToken.raw,
Location: "/",
},
proxy: apiContext.proxy,
};

const res: io.Response = await io.post(requestOptions);
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/decline-contact-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function declineContactRequest(
headers: {
"X-Skypetoken": apiContext.skypeToken.value,
},
proxy: apiContext.proxy,
};
const res: io.Response = await io.put(requestOptions);

Expand Down
Loading