Coder Social home page Coder Social logo

zackmwangi / stream-chat-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getstream/stream-chat-js

0.0 0.0 0.0 4.03 MB

JS / Browser Client - Build Chat with GetStream.io

Home Page: https://getstream.io/chat/

License: Other

JavaScript 35.33% TypeScript 64.67%

stream-chat-js's Introduction

Official JavaScript SDK for Stream Chat

NPM

Official JavaScript API client for Stream Chat, a service for building chat applications.
Explore the docs ยป

Report Bug ยท Request Feature

๐Ÿ“ About Stream

You can sign up for a Stream account at our Get Started page.

This library can be used by both frontend and backend applications. For frontend, we have frameworks that are based on this library such as the Flutter, React and Angular SDKs. For more information, check out our docs.

โš™๏ธ Installation

NPM

npm install stream-chat

Yarn

yarn add stream-chat

JS deliver

<script src="https://cdn.jsdelivr.net/npm/stream-chat"></script>

โœจ Getting started

The StreamChat client is setup to allow extension of the base types through use of generics when instantiated. The default instantiation has all generics set to Record<string, unknown>.

import { StreamChat } from 'stream-chat';
// Or if you are on commonjs
const StreamChat = require('stream-chat').StreamChat;

const client = StreamChat.getInstance('YOUR_API_KEY', 'API_KEY_SECRET');

const channel = client.channel('messaging', 'TestChannel');
await channel.create();

Or you can customize the generics:

type ChatChannel = { image: string; category?: string };
type ChatUser1 = { nickname: string; age: number; admin?: boolean };
type ChatUser2 = { nickname: string; avatar?: string };
type UserMessage = { country?: string };
type AdminMessage = { priorityLevel: number };
type ChatAttachment = { originalURL?: string };
type CustomReaction = { size?: number };
type ChatEvent = { quitChannel?: boolean };
type CustomCommands = 'giphy';

type StreamType = {
  attachmentType: ChatAttachment;
  channelType: ChatChannel;
  commandType: CustomCommands;
  eventType: ChatEvent;
  messageType: UserMessage | AdminMessage;
  reactionType: CustomReaction;
  userType: ChatUser1 | ChatUser2;
};

const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY', 'API_KEY_SECRET');

// Create channel
const channel = client.channel('messaging', 'TestChannel');
await channel.create();

// Create user
await client.upsertUser({
  id: 'vishal-1',
  name: 'Vishal',
});

// Send message
const { message } = await channel.sendMessage({ text: `Test message` });

// Send reaction
await channel.sendReaction(message.id, { type: 'love', user: { id: 'vishal-1' } });

Custom types provided when initializing the client will carry through to all client returns and provide intellisense to queries.

๐Ÿ“š More code examples

Head over to docs/typescript.md for more examples.

โœ๏ธ Contributing

We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.

Head over to CONTRIBUTING.md for some development tips.

๐Ÿง‘โ€๐Ÿ’ป We are hiring!

We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.

Check out our current openings and apply via Stream's website.

stream-chat-js's People

Contributors

vishalnarkhede avatar thesyncim avatar tbarbugli avatar nhannah avatar mahboubii avatar ferhatelmas avatar gumuz avatar link512 avatar tschellenbach avatar bdandy avatar anatolyrugalev avatar ruudniew avatar jeltef avatar miagilepner avatar bogdan-d avatar peterdeme avatar yaziine avatar github-actions[bot] avatar dependabot[bot] avatar ruggi avatar bogdan-getstream avatar zerozez avatar khushal87 avatar ravlio avatar ffenix113 avatar keyneston avatar walberty avatar vicnicius avatar tsirlucas avatar virdesai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.