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

sendbird-nodejs

v1.0.0

Published

Thin wrapper around SendBird Server REST API v3

Downloads

157

Readme

sendbird-nodejs

Thin wrapper around SendBird's Platform API

Installation

npm install sendbird-nodejs --save

or

yarn add sendbird-nodejs

Usage

See SendBird Documentation for payload and response details.
You must provide your API Token when creating a new instance of SendBird and it will be attached to all requests.

var SendBird = require('sendbird-nodejs');
var sb = new SendBird(/* your sendbird api token here */);

The sb instance we just created has an entry for each endpoint in the SendBird Platform API, it is an object with the endpoints methods.
Note that all methods return a Promise as returned by request-promise.

sb.users

sb.openChannels
sb.openChannels.messages
sb.openChannels.metadata
sb.openChannels.metacounter

sb.groupChannels
sb.groupChannels.messages
sb.groupChannels.metadata
sb.groupChannels.metacounter

Missing endpoints

sb.applications
sb.migration
sb.bots

Example

To create a user you would simply need to have something like this:

const SendBird = require('sendbird-nodejs');
const sb = SendBird('<SOME API TOKEN>');

const payload = {
    "user_id": string,
    "nickname": string,
    "profile_url": string,
    "issue_access_token": boolean // (Optional)
};
sb.users.create(payload)
    .then(function (response) {
        // do something with SendBird response
        // {
        //     "user_id": string,
        //     "nickname": string,
        //     "profile_url": string,
        //     "access_token": string,
        //     "last_seen_at": long,
        //     "is_online": boolean
        // }
    });

There are two different types of parameters the Platform API requires

  1. url params - you can see them in sendbird docs as {some_param} in the URL
  2. payload/querystring params - you can see them in the sendbird docs under the request section

We will treat the two types differently when calling the API.
url params will be used as arguments for the API method you are calling.
payload/querystring params will always a plain object and the last argument of the API method.

This is how we would send a message to a group channel on behalf of some user using the API: Send Message Docs

const SendBird = require('sendbird-nodejs');
const sb = SendBird('<SOME API TOKEN>');

const channelUrl = 'channel-url-from-sendbird';
const payload = {
    "message_type": "MESG",       // Text message
    "user_id": string,            // Sender user_id
    "message": string,            // Empty string is not allowed.
    "data": string,               // (Optional) Custom data 
    "custom_type": string,        // (Optional) default: ''  
    "mark_as_read": boolean       // (Optional) default: true  
};
sb.groupChannels.messages.send(channelUrl, payload)
    .then(function (response) {
        // do something with SendBird response
        // {
        //     "message_id": long,
        //     "type": "MESG",
        //     "message": string,
        //     "file": {
        //         "name": string,
        //         "url": string,
        //         "type": string,
        //         "size": int
        //     },
        //     "data": string,
        //     "channel_url": string,
        //     "created_at": long,
        //     "user": {
        //         "nickname": string,
        //         "user_id": string,
        //         "profile_url": string
        //     },
        //     "custom_type": string
        // }
    });

In the docs we see the URL is https://api.sendbird.com/v3/{channel_type}/{channel_url}/messages so the channel_type param will be set by using sb.groupChannels and the channel_url is the first argument we of sb.groupChannels.message.send

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D