1.0.12 • Published 2 years ago

sendbird-await v1.0.12

Weekly downloads
250
License
-
Repository
github
Last release
2 years ago

sendbird-await

Sendbird await module for Platform API

Requirements

node v8.4.0 Higher

Installation

npm install sendbird-await --save

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.

const SendbirdAwait = require('sendbird-await');
let Sendbird = new SendbirdAwait(/* sendbird api token here */);

The Sendbird instance we just created has an entry for each endpoint in the Sendbird Platform API, it is an object with the endpoints methods.

Sendbird.user Sendbird.openchannel Sendbird.groupchannel Sendbird.message Sendbird.metadata

Example

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

'use strict';

const SendbirdAwait = require('sendbird-await');
let Sendbird = new SendbirdAwait('<YOUR API TOKEN>');

class Test {
    async userList() {
        let users = await Sendbird.user.list();
        return users;
    }

    async userCreate() {
        let params = {
            user_id: 'nexus11',
            nickname: 'sendbirdFirstUser',
            profile_url: 'https://yourimages.location.url'
        };
        let user = await Sendbird.user.create(params);
        return user;
    }

    async createOpenChannel() {
        let params = {
            name: 'FirstOpenChannel'
        };
        let openChannel = await Sendbird.openchannel.create(params);
        return openChannel;
    }

    async createGroupChannel() {
        let params = {
            name: 'FirstGroupChannel',
            is_public: true
        };
        let groupChannel = await Sendbird.groupchannel.create(params);
        return groupChannel;
    }

    async sendMessage() {
        let params = {
            channel_type: 'group_channels',
            channel_url: '<Sendbird group channel name>' // ex) sendbird_group_channel_123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZ,
            user_id: 'nexus11',
            message: 'Hi, First messgae!',
            message_type: 'MESG' //MESG, FILE, ADMM
        };
        let msg = await Sendbird.message.send(params);
        return msg;
    }
}

module.exports = new Test();

[test for NodeJS CLI]
$> node -e 'require("./Test").createOpenChannel()'
1.0.12

2 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago