Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
183 lines (140 sloc) 6.76 KB

spark-js-sdk

Greenkeeper badge

npm license Build status

The Cisco Webex JS SDK

Cisco Spark is now Webex Teams! You will notice changes to our documentation and packages as we update over the next several weeks. Read why this is more than just a rebrand.

This is a monorepo containing all officially maintained Cisco Webex JS SDK modules in the same repo.

ciscospark is a collection of node modules targeting our external APIs.

Install

We test against the Active LTS (Long Term Support) version of Node.js and use npm@6 to run security audits.

To install the latest stable version of the SDK from NPM:

npm install --save ciscospark

Usage

To use the SDK, you will need Cisco Webex credentials. If you do not already have a Cisco Webex account, visit Cisco Webex for Developers to create your account and retrieve your access token.

See the detailed docs for more usage examples.

const ciscospark = require(`ciscospark`);
const teams = ciscospark.init({
  credentials: {
    access_token: <your webex teams access token>
  }
});

// Create a room with the title "My First Room"
// Add Alice and Bob to the room
// Send a **Hi Everyone** message to the room
teams.rooms.create({ title: `My First Room` }).then(room => {
  return Promise.all([
    ciscospark.memberships.create({
      roomId: room.id,
      personEmail: `alice@example.com`
    }),
    ciscospark.memberships.create({
      roomId: room.id,
      personEmail: `bob@example.com`
    })
  ]).then(() =>
    ciscospark.messages.create({
      markdown: `**Hi Everyone**`,
      roomId: room.id
    })
  );
});

A note on browser usage

We do not provide a built version of the SDK that includes window.ciscospark. In-browser usage is almost the same as Node.js, but it handles the user authentication flow for you. See the browser guide for more information.

If you're already using a bundler (like Webpack or Rollup) you can simply import/require the package and use the above snippet and assign the initialized team variable to window.webexteams. For a quick example, we'll use Parcel to bundle the SDK for a website. For any more information and questions on how to use Parcel, please head to their website.

  1. Create index.js.
import { init as initTeams } from 'ciscospark';

// Initialize the SDK and make it available to the window
const teams = (window.webexteams = initTeams({
  credentials: {
    access_token: <your webex teams access token>
  }
}));

// Create a room with the title "My First Room"
teams.rooms
  .create({
    title: 'My First Room!'
  })
  .catch((error) => {
    console.error(error);
  });

// Filter for "My First Room" from the last 10 rooms
teams.rooms
  .list({
    max: 10
  })
  .then((rooms) => {
    // Destructure room properties for it's id (aliased to roomId) and title
    const { id: roomId, title } = rooms.items.filter(
      room => room.title === 'My First Room!'
    )[0];

    // Post message "Hello World!" to "My First Room!"
    teams.messages.create({
      roomId,
      text: 'Hello World!'
    });

    // Log the the room name and the message we created
    return teams.messages
      .list({ roomId, max: 1 })
      // Destructure promised value to get text property from first item in items array
      .then(({ items: [{ text }] }) =>
        console.log(`Last message sent to room "${title}": ${text}`)
      );
  })
  .catch((error) => {
    console.error(error);
  });
  1. Create index.html .
<html>
  <head>
    <title>Webex SDK for Browsers</title>
  </head>
  <body>
    <script src="./index.js"></script>
  </body>
</html>
  1. Run parcel index.html in your terminal.
  2. Go to http://localhost:1234 and open the developer console to see the output.

Still using ciscospark/env?

Samples

Sample code can be found in packages/node_modules/samples. You can run them yourself with the following commands:

Note: This installs all of the SDK's tooling dependencies, so you'll need libgcrypt and (possibly) graphicsmagick. On a mac, you can install these with brew install graphicsmagick libgcrypt.

git clone git@github.com:webex/spark-js-sdk.git
cd spark-js-sdk
npm install
npm run samples:serve

You'll be able to load the samples by visiting https://localhost:8000/packages/node_modules/samples/<PACKAGE NAME>.

Available Samples

Sample App Link Source
Implicit Grant Flow local app code
Single Party Calling local app code
Single Party Calling with Mute local app code
Multi Party Calling local app code
Call with Content Sharing local app code

Contribute

Pull requests welcome. Please see CONTRIBUTING.md for more details about building the packages and submitting pull requests for suggested changes.

License

© 2016-2018 Cisco and/or its affiliates. All Rights Reserved.

See LICENSE for details.