npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-sparky

v3.1.22

Published

Spark SDK for NodeJS

Downloads

497

Readme

node-sparky

NPM

Cisco Spark SDK for Node JS (Version 3)

var Spark = require('node-sparky');

var spark = new Spark({ token: '<my token>' });

spark.roomsGet(10)
  .then(function(rooms) {
    // process rooms as array
    rooms.forEach(function(room) {
      console.log(room.title);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

If you are coming from using node-sparky version 2.x or earlier, note that the architecture, commands, and some variable names have changed. While this release is similar to previous versions, there are some major differences. Please read the API docs below before migrating your code to this release. If you are looking for the old release version, [email protected] is still available to be installed through NPM.

Features

  • Built in rate limiter and outbound queue that allows control over the number of parallel API calls and the minimum time between each call.
  • Transparently handles 429 (and/or other customizable) http errors and re-queues those requests.
  • File processor for retrieving attachments from room.
  • Event emitters tied to request, response, error, retry, and queue drops.
  • Returns promises that comply with A+ standards..
  • Handles pagination transparently. (Receive unlimited records)
  • (new) Support for Spark API Advanced Webhooks
  • (new) Support Teams API
  • (new) Support for markdown formatted messages
  • (new) Support for authenticated HMAC-SHA1 webhooks

Installation

This module can be installed via NPM:

npm install node-sparky --save

Reference

Initialization and Configuration

var Spark = require('node-sparky');

var spark = new Spark({
  token: 'mytoken',
  webhookUrl: 'http://mywebhook.url/path',
});

Classes

Objects

Events

Spark

Kind: global class
Throw: Error Throws on spark token missing in options object.

new Spark(options)

Creates a Spark API instance that is then attached to a Spark Account.

| Param | Type | Description | | --- | --- | --- | | options | Object | Configuration object containing Spark settings |

spark.options : object

Options Object

Kind: instance namespace of Spark
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | token | string | | Spark Token. | | webhookUrl | string | | URL that is used for SPark API to send callbacks. | | webhookSecret | string | | If specified, creates webhooks using this secret. The incoming webhook must still be authenticated. See Spark.webhookAuth(). | | maxPageItems | number | 50 | Max results that the paginator uses. | | maxConcurrent | number | 3 | Max concurrent sessions to the Spark API | | minTime | number | 600 | Min time between consecutive request starts. | | requeueMinTime | number | minTime*10 | Min time between consecutive request starts of requests that have been re-queued. | | requeueMaxRetry | number | 3 | Msx number of atteempts to make for failed request. | | requeueCodes | array | [429,500,503] | Array of http result codes that should be retried. | | requestTimeout | number | 20000 | Timeout for an individual request recieving a response. | | queueSize | number | 10000 | Size of the buffer that holds outbound requests. | | requeueSize | number | 10000 | Size of the buffer that holds outbound re-queue requests. |

spark.roomsGet([max]) ⇒ Promise.<Array>

Return all Spark Rooms registered to account.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.roomsGet(10)
  .then(function(rooms) {
    // process rooms as array
    rooms.forEach(function(room) {
      console.log(room.title);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomsDirect([max]) ⇒ Promise.<Array>

Return all Spark 1:1 Rooms.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.roomsDirect(10)
  .then(function(rooms) {
    // process rooms as array
    rooms.forEach(function(room) {
      console.log(room.title);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomsGroup([max]) ⇒ Promise.<Array>

Return all Spark Group Rooms.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.roomsGroup(10)
  .then(function(rooms) {
    // process rooms as array
    rooms.forEach(function(room) {
      console.log(room.title);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomsByTeam(teamId, [max]) ⇒ Promise.<Array>

Return all Spark Rooms for a particular Team ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | The Spark Team ID | | [max] | Integer | Number of records to return |

Example

spark.roomsByTeam('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 10)
  .then(function(rooms) {
    // process rooms as array
    rooms.forEach(function(room) {
      console.log(room.title);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomGet(roomId) ⇒ Promise.<Room>

Return details of Spark Room by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID |

Example

spark.roomGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(room) {
    console.log(room.title);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomAdd(title) ⇒ Promise.<Room>

Add new Spark Room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | title | String | Title for new Room |

Example

spark.roomAdd('myroom')
  .then(function(room) {
    console.log(room.title);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomRename(roomId, title) ⇒ Promise.<Room>

Rename Spark Room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | title | String | Title for new Room |

Example

spark.roomRename('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 'myroom2')
  .then(function(room) {
    console.log(room.title);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.roomRemove(roomId) ⇒ Promise

Remove Spark Room by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID |

Example

spark.roomRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Room removed.');
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.peopleSearch(displayName, [max]) ⇒ Promise.<Array>

Search Spark for People by display name.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | displayName | String | Search String to find as display name | | [max] | Integer | Number of records to return |

Example

spark.peopleSearch('John', 10)
  .then(function(people) {
    // process people as array
    people.forEach(function(person) {
      console.log(person.displayName);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.personGet(personId) ⇒ Promise.<Person>

Return details of Spark User by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | personId | String | Spark Person ID |

Example

spark.personGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(person) {
    console.log(person.displayName);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.personMe() ⇒ Promise.<Person>

Return details of Spark User that has authenticated.

Kind: instance method of Spark
Example

spark.personMe()
  .then(function(person) {
    console.log(person.displayName);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.personByEmail(email) ⇒ Promise.<Person>

Return details of Spark User by Email.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | email | String | Email address of Spark User |

Example

spark.personByEmail('[email protected]')
  .then(function(person) {
    console.log(person.displayName);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.attachmentActionGet(attachmentActionId) ⇒ Promise.<AttachmentAction>

Return details of an attachment action by ID.

Kind: instance method of Spark
Returns: Promise.<AttachmentAction> - AttachmentAction object

| Param | Type | Description | | --- | --- | --- | | attachmentActionId | String | AttachmentAction ID |

Example

spark.attachmentActionGet('Tm90aGluZyB0byBzZWUgaGVy')
  .then(attachmentAction => console.log(attachmentAction))
  .catch(err => console.error(err));

spark.attachmentActionCreate(attachmentAction) ⇒ Promise.<AttachmentAction>

Create an Attachment Action.

Kind: instance method of Spark
Returns: Promise.<AttachmentAction> - AttachmentAction object

| Param | Type | Description | | --- | --- | --- | | attachmentAction | Object.<AttachmentAction> | Attachment Action to create |

Example

const newAttachmentAction = {
  type: 'submit',
  messageId: 'Tm90aGluZyB0byBzZWUgaGVy',
  "inputs": {
     "Name": "John Andersen",
     "Url": "https://example.com",
     "Email": "[email protected]",
     "Tel": "+1 408 526 7209"
    }
}

spark.attachmentActionCreate(newAttachmentAction)
  .then(attachmentAction => console.log(attachmentAction.id))
  .catch(err => console.error(err));

spark.messagesGet(roomId, [max]) ⇒ Promise.<Array>

Return messages in a Spark Room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | [max] | Integer | Number of records to return |

Example

spark.messagesGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 100)
  .then(function(messages) {
    // process messages as array
    messages.forEach(function(message) {
      console.log(message.text);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.messageGet(messageId) ⇒ Promise.<Message>

Return details of Spark Message by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | messageId | String | Spark Message ID |

Example

spark.messageGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 100)
  .then(function(message) {
    console.log(message.text);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.messageSendPerson(email, message) ⇒ Promise.<Message>

Sends 1:1 Spark message to a person.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | email | String | Email address of Spark User | | message | Object | Message Object |

Example

spark.messageSendPerson('[email protected]', {
    text: 'Hello!',
    files: ['http://company.com/myfile.doc']
  })
  .then(function(message) {
    console.log('Message sent: %s', message.txt) ;
  })
  .catch(function(err){
    console.log(err);
  });

spark.messageSendRoom(roomId, message) ⇒ Promise.<Message>

Sends Spark message to a room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | message | Object | Message Object |

Example

spark.messageSendRoom('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', {
    text: 'Hello!',
    files: ['http://company.com/myfile.doc']
  })
  .then(function(message) {
    console.log('Message sent: %s', message.txt);
  })
  .catch(function(err){
    console.log(err);
  });

spark.messageStreamRoom(roomId, message) ⇒ Promise.<Message>

Streams Spark message to a room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | message | Object | Message Object |

Example

var roomId = 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u';
var text = 'Hello';
var filename = 'test.png';
var stream = fs.createReadStream(filename);
var message = { 'text': text, 'filename': filename, 'stream': stream };
spark.messageStreamRoom(roomId, message)
  .then(function(message) {
    console.log('Message sent: %s', message.txt);
  })
  .catch(function(err){
    console.log(err);
  });

spark.upload(roomId, filepath) ⇒ Promise.<Message>

Upload a file by path to Spark Room

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | filepath | String | path to file |

Example

var roomId = 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u';
spark.upload(roomId, '/some/local/file.png');

spark.messageRemove(messageId) ⇒ Promise

Remove Spark Message by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | messageId | String | Spark Message ID |

Example

spark.messageRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Message removed.');
  })
  .catch(function(err){
    console.log(err);
  });

spark.contentGet(id) ⇒ Promise.<File>

Return details of Spark File by Content ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | id | String | Spark Content ID |

Example

spark.contentGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(file) {
    console.log('File name: %s', file.name);
  })
  .catch(function(err){
    console.log(err);
  });

spark.contentByUrl(url) ⇒ Promise.<File>

Return details of Spark File by Spark Content URL.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | url | String | Spark Content URL |

Example

spark.contentByUrl('http://api.ciscospark.com/v1/contents/Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(file) {
    console.log('File name: %s', file.name);
  })
  .catch(function(err){
    console.log(err);
  });

spark.teamsGet([max]) ⇒ Promise.<Array>

Return all Spark Teams registered to account.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.teamsGet(10)
  .then(function(teams) {
    // process teams as array
    teams.forEach(function(team) {
      console.log(team.name);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamGet(teamId) ⇒ Promise.<Team>

Return details of Spark Team by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID |

Example

spark.teamGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(team) {
    console.log(team.name);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamAdd(name) ⇒ Promise.<Team>

Add new Spark Team.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | name | String | Name for new Team |

Example

spark.teamAdd('myteam')
  .then(function(team) {
    console.log(team.name);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamRoomAdd(teamId, title) ⇒ Promise.<Room>

Add new Spark Team Room.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID | | title | String | Title for new Room |

Example

spark.teamRoomAdd('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 'myroom')
  .then(function(room) {
    console.log(room.title);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamRename(teamId, name) ⇒ Promise.<Team>

Rename a Spark Team.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID | | name | String | Name for new Team |

Example

spark.teamRename('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 'myteam2')
  .then(function(team) {
    console.log(team.name);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamRemove(teamId) ⇒ Promise

Remove Spark Team by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID |

Example

spark.teamRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Team removed.');
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamMembershipsGet(teamId, [max]) ⇒ Promise.<Array>

Return all Spark Team Memberships for a specific Team.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID | | [max] | Integer | Number of records to return |

Example

spark.teamMembershipsGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 100)
  .then(function(memberships) {
    // process memberships as array
    memberships.forEach(function(membership) {
      console.log(membership.personEmail);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.teamMembershipGet(membershipId) ⇒ Promise.<TeamMembership>

Return Spark Team Membership by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.membershipGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log(membership.personEmail);
  })
  .catch(function(err){
    console.log(err);
  });

spark.teamMembershipAdd(teamId, email, moderator) ⇒ Promise.<TeamMembership>

Add new Spark Team Membership.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | teamId | String | Spark Team ID | | email | String | Email address of person to add | | moderator | Boolean | Boolean value to add as moderator |

Example

spark.teamMembershipAdd('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', '[email protected]')
  .then(function(membership) {
    console.log(membership.id);
  })
  .catch(function(err){
    console.log(err);
  });

spark.teamMembershipSetModerator(membershipId) ⇒ Promise.<TeamMembership>

Set a Team Membership as moderator.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.teamMembershipSetModerator('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log('%s is a moderator: %s', membership.personEmail, membership.isModerator);
  })
  .catch(function(err){
    console.log(err);
  });

spark.teamMembershipClearModerator(membershipId) ⇒ Promise.<TeamMembership>

Remove a Team Membership as moderator.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.teamMembershipClearModerator('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log('%s is a moderator: %s', membership.personEmail, membership.isModerator);
  })
  .catch(function(err){
    console.log(err);
  });

spark.teamMembershipRemove(membershipId) ⇒ Promise

Remove Spark Team Membership by ID..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.teamMembershipRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Membership removed');
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipsGet([max]) ⇒ Promise.<Array>

Return all Spark Memberships registered to account..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.membershipsGet(100)
  .then(function(memberships) {
    // process memberships as array
    memberships.forEach(function(membership) {
      console.log(membership.personEmail);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.membershipsByRoom(roomId, [max]) ⇒ Promise.<Array>

Return all Spark Memberships in a Spark Room..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | [max] | Integer | Number of records to return |

Example

spark.membershipsByRoom('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', 100)
  .then(function(memberships) {
    // process memberships as array
    memberships.forEach(function(membership) {
      console.log(membership.personEmail);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.membershipGet(membershipId) ⇒ Promise.<Membership>

Return Spark Membership by ID..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.membershipGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log(membership.personEmail);
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipByRoomByEmail(roomId, personEmail) ⇒ Promise.<Membership>

Return Spark Membership by Room and Email..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Membership ID | | personEmail | String | Email of Person |

Example

spark.membershipByRoomByEmail('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', '[email protected]')
  .then(function(membership) {
    console.log(membership.id);
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipAdd(roomId, email, moderator) ⇒ Promise.<Membership>

Add new Spark Membership..

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | roomId | String | Spark Room ID | | email | String | Email address of person to add | | moderator | Boolean | Boolean value to add as moderator |

Example

spark.membershipAdd('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u', '[email protected]')
  .then(function(membership) {
    console.log(membership.id);
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipSetModerator(membershipId) ⇒ Promise.<Membership>

Set a Membership as moderator.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.membershipSetModerator('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log('%s is a moderator: %s', membership.personEmail, membership.isModerator);
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipClearModerator(membershipId) ⇒ Promise.<Membership>

Remove a Membership as moderator.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.membershipClearModerator('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(membership) {
    console.log('%s is a moderator: %s', membership.personEmail, membership.isModerator);
  })
  .catch(function(err){
    console.log(err);
  });

spark.membershipRemove(membershipId) ⇒ Promise

Remove Spark Membership by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | membershipId | String | Spark Membership ID |

Example

spark.membershipRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Membership removed');
  })
  .catch(function(err){
    console.log(err);
  });

spark.webhooksGet([max]) ⇒ Promise.<Array>

Return all Spark Webhooks registered to account.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | [max] | Integer | Number of records to return |

Example

spark.webhooksGet(100)
  .then(function(webhooks) {
    // process webhooks as array
    webhooks.forEach(function(webhook) {
      console.log(webhook.name);
    });
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.webhookGet(webhookId) ⇒ Promise.<Webhook>

Return details of Spark Webhook by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | webhookId | String | Spark Webhook ID |

Example

spark.webhookGet('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(webhook) {
    console.log(webhook.name);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.webhookAdd(resource, event, name, [filter]) ⇒ Promise.<Webhook>

Add new Spark Webhook.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | resource | String | Resource for webhook | | event | String | Event for webhook | | name | String | Name assigned to webhook to add | | [filter] | String | filter |

Example

spark.webhookAdd('messages', 'created', 'mywebhook', 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function(webhook) {
    console.log(webhook.name);
  })
  .catch(function(err) {
    // process error
    console.log(err);
  });

spark.webhookRemove(webhookId) ⇒ Promise

Remove Spark Webhook by ID.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | webhookId | String | Spark Webhook ID. |

Example

spark.webhookRemove('Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u')
  .then(function() {
    console.log('Webhook removed');
  })
  .catch(function(err){
    console.log(err);
  });

spark.webhookAuth(signature, payload) ⇒ Boolen

Authenticate X-Spark-Signature HMAC-SHA1 Hash.

Kind: instance method of Spark

| Param | Type | Description | | --- | --- | --- | | signature | String | Value of "X-Spark-Signature" from header | | payload | String | Object | This can either be the json object or a string representation of the webhook's body json payload |

Example

var sig = req.headers['x-spark-signature'];
if(spark.webhookAuth(sig, req.body)) {
  // webhook is valid
} else {
  // webhook is invalid
}

Room : object

Room Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Room ID | | title | string | Room Title | | type | string | Room Type | | isLocked | boolean | Room Moderated/Locked | | teamId | string | Team ID | | lastActivity | date | Last Activity in Room | | created | date | Room Created |

Person : object

Person Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Person ID | | emails | array | Emails | | displayName | string | Display Name | | avatar | string | Avatar URL | | created | date | Date created | | email | string | Email | | username | string | Username | | domain | string | Domain name |

Message : object

Message Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Message ID | | personId | string | Person ID | | personEmail | string | Person Email | | roomId | string | Room ID | | text | string | Message text | | files | array | Array of File objects | | created | date | Date Message created |

File : object

File Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Spark API Content ID | | name | string | File name | | ext | string | File extension | | type | string | Header [content-type] for file | | binary | buffer | File contents as binary | | base64 | string | File contents as base64 encoded string |

Team : object

Team Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Message ID | | name | string | Team name | | created | date | Date Team created |

TeamMembership : object

Team Membership Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Membership ID | | teamId | string | Team ID | | personId | string | Person ID | | personEmail | string | Person Email | | isModerator | boolean | Membership is a moderator | | created | date | Date Membership created |

Membership : object

Membership Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Membership ID | | personId | string | Person ID | | personEmail | string | Person Email | | isModerator | boolean | Membership is a moderator | | isMonitor | boolean | Membership is a monitor | | created | date | Date Membership created |

Webhook : object

Webhook Object

Kind: global namespace
Properties

| Name | Type | Description | | --- | --- | --- | | id | string | Webhook ID | | name | string | Webhook name | | targetUrl | string | Webhook target URL | | resource | boolean | Webhook resource | | event | boolean | Webhook event | | filter | boolean | Webhook filter | | created | date | Date Webhook created |

Validator : object

Spark Validation functions.

Kind: global namespace

Validator.isEmail(email) ⇒ Boolean

Validate String is Email.

Kind: static method of Validator

| Param | Type | | --- | --- | | email | String |

Validator.isUrl(url) ⇒ Boolean

Validate String is URL.

Kind: static method of Validator

| Param | Type | | --- | --- | | url | String |

Validator.isFilePath(path) ⇒ Boolean

Validate String is File path.

Kind: static method of Validator

| Param | Type | | --- | --- | | path | String |

Validator.isRoom(object) ⇒ Boolean

Validate Spark Room Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Room |

Validator.isPerson(object) ⇒ Boolean

Validate Spark Person Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Room |

Validator.isMessage(object) ⇒ Boolean

Validate Spark Message Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Message |

Validator.isMembership(object) ⇒ Boolean

Validate Spark Membership Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Membership |

Validator.isWebhook(object) ⇒ Boolean

Validate Spark Webhook Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Webhook |

Validator.isTeam(object) ⇒ Boolean

Validate Spark Team Object.

Kind: static method of Validator

| Param | Type | | --- | --- | | object | Team |

Validator.isRooms(rooms) ⇒ Boolean

Validate Spark Room Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | rooms | Array |

Validator.isPeople(persons) ⇒ Boolean

Validate Spark Person Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | persons | Array |

Validator.isMessages(messages) ⇒ Boolean

Validate Spark Message Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | messages | Array |

Validator.isMemberships(memberships) ⇒ Boolean

Validate Spark Membership Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | memberships | Array |

Validator.isWebhooks(webhooks) ⇒ Boolean

Validate Spark Webhook Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | webhooks | Array |

Validator.isTeams(teams) ⇒ Boolean

Validate Spark Team Objects in Array.

Kind: static method of Validator

| Param | Type | | --- | --- | | teams | Array |

"drop"

Spark Queue Drop Event.

Kind: event emitted
Properties

| Name | Type | Description | | --- | --- | --- | | request | options | API Request | | id | string | Spark UUID |

"request"

Spark request event.

Kind: event emitted
Properties

| Name | Type | Description | | --- | --- | --- | | request | options | API Request | | id | string | Spark UUID |

"reponse"

Spark response event.

Kind: event emitted
Properties

| Name | Type | Description | | --- | --- | --- | | response | options | Response | | id | string | Spark UUID |

"retry"

Spark retry event.

Kind: event emitted
Properties

| Name | Type | Description | | --- | --- | --- | | request | options | API Request | | id | string | Spark UUID |

License

The MIT License (MIT)

Copyright (c) 2016-2017

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.