0.0.3 • Published 2 years ago

@platohq/nestjs-sendbird v0.0.3

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

@platohq/nestjs-sendbird

The NestJS module based on the official Sendbird REST APIs

How to install

npm install @platohq/nestjs-sendbird

or

yarn add @platohq/nestjs-sendbird

How to use

Register the module

import { SendbirdModule } from '@platohq/nestjs-sendbird';

@Module({
  imports: [
    SendbirdModule.register({
      baseURL: process.env.SENDBIRD_BASE_URL,
      headers: {
        'Api-Token': process.env.SENDBIRD_API_TOKEN,
      },
    }),
  ],
})
export class AppModule {
}

Inject the service

import { SendbirdService } from '@platohq/nestjs-sendbird';

@Injectable()
export class AppService {
  constructor(private readonly sendbirdService: SendbirdService) {
  }

  private async createUser(user: User): Promise<string> {
    const sendbirdAccessToken = await this.sendbirdService.createUser(
      user.id,
      user.fullName,
      user.avatarUrl,
    );

    return sendbirdAccessToken;
  }
}

Async options

Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync() method, that provides a couple of various ways to deal with async data.

Use factory

SendbirdModule.registerAsync({
  useFactory: () => ({
    baseURL: process.env.SENDBIRD_BASE_URL,
    headers: {
      'Api-Token': process.env.SENDBIRD_API_TOKEN,
    }
  }),
});