Giter Club home page Giter Club logo

chatkit-server-node's Introduction

Chatkit Retirement Announcement

We are sorry to say that as of April 23 2020, we will be fully retiring our Chatkit product. We understand that this will be disappointing to customers who have come to rely on the service, and are very sorry for the disruption that this will cause for them. Our sales and customer support teams are available at this time to handle enquiries and will support existing Chatkit customers as far as they can with transition. All Chatkit billing has now ceased , and customers will pay no more up to or beyond their usage for the remainder of the service. You can read more about our decision to retire Chatkit here: https://blog.pusher.com/narrowing-our-product-focus. If you are interested in learning about how you can build chat with Pusher Channels, check out our tutorials.

chatkit-server-node

Twitter GitHub license npm version Read the docs

The Node.js server SDK for Pusher Chatkit.

Installation

yarn:

$ yarn add @pusher/chatkit-server

npm:

$ npm install @pusher/chatkit-server --save

Getting started

Head over to our documentation.

Publishing

Running npm run publish-please will walk you through the publishing steps.

chatkit-server-node's People

Contributors

benpope avatar callum-oakley avatar elverkilde avatar gildebrand avatar hamchapman avatar jonathanlloyd avatar matthewdking avatar mdpye avatar minaorangina avatar samuelyallop-pusher avatar vivangkumar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatkit-server-node's Issues

Chatkit Node JS updateUser does not propagate changes to Swift & Android clients

What?

In node JS we update the user's name or avatarURL as shown below but those changes are not propagated to the rooms and users in the rooms of that user.

var updateUserArgs = {
id: userId,
name: name,
avatarURL: avatarURL,
}

await chatkit.updateUser(updateUserArgs)
.then(() => {
console.log('User " + userId + " updated successfully');
}).catch((err) => {
console.log(err);
reportError("/updateUser failed because invalid userId " + userId)
})

Suggested improvements

We'd like to be able to update the user's avatarURL and name updated for all users connected to all rooms with that user in it and also have that their user info updated for anyone receiving messages from them.

Upgrade jsonwebtoken dependency to fix vulnerability

What?

❌ High severity vulnerability found in base64url
Description: Uninitialized Memory Exposure
Info: https://snyk.io/vuln/npm:base64url:20180511
Introduced through: @pusher/[email protected]
From: @pusher/[email protected] > [email protected] > [email protected] > [email protected]
From: @pusher/[email protected] > [email protected] > [email protected] > [email protected] > [email protected]
From: @pusher/[email protected] > [email protected] > [email protected] > [email protected] > [email protected] > [email protected]
and 3 more...
Remediation:
~~Your dependencies are out of date, otherwise you would be using a newer version of base64url.
Try deleting node_modules, reinstalling and running snyk test again. If the problem persists,~~~ one of your dependencies may be bundling outdated modules.

Suggested improvements

They fixed it this PR:
auth0/node-jsonwebtoken#465

getRooms members_list data is always null / different to user.getRooms

What?

I'm using a query getRooms
https://docs.pusher.com/chatkit/reference/server-node#get-rooms

this shows every room has an empty member_user_ids
but when I iterate through the users, with getUserRooms it shows different info.

This is after using your console, and also trying manually to add users to rooms.

Suggested improvements

If a user is in a room, then they should show up in that room when using the API to check room info.

for all rooms you can see the 'lobby' is supposedly empty:

  Rabbit all rooms=> [ { created_at: '2019-01-28T06:31:30Z',
    created_by_id: 'dcsan',
    id: '19398582',
    member_user_ids: null,
    name: 'lobby',
    private: false,
    updated_at: '2019-01-28T06:31:30Z' },
  { created_at: '2019-02-15T07:13:27Z',
    created_by_id: 'genie',
    id: '19408194',
    member_user_ids: null,
    name: 'testing',
    private: false,
    updated_at: '2019-02-15T07:13:27Z' },
  { created_at: '2019-02-15T07:17:03Z',
    created_by_id: 'genie',
    id: '19408196',
    member_user_ids: null,
    name: 'empty',
    private: false,
    updated_at: '2019-02-15T07:17:03Z' } ] +302ms

when using a different API and checking a user's rooms, the lobby and other rooms now have members:

  Rabbit getUserRooms result=> Promise { <pending> } +1ms
  Rabbit userStatus for userId: dcsan +1ms
  Rabbit getUserRooms.then res [ { created_at: '2019-01-28T06:31:30Z',
    created_by_id: 'dcsan',
    id: '19398582',
    member_user_ids: [ 'adminBot', 'dcsan', 'genie' ],
    name: 'lobby',
    private: false,
    updated_at: '2019-01-28T06:31:30Z' },
  { created_at: '2019-02-15T07:13:27Z',
    created_by_id: 'genie',
    id: '19408194',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'testing',
    private: false,
    updated_at: '2019-02-15T07:13:27Z' },
  { created_at: '2019-02-15T07:17:03Z',
    created_by_id: 'genie',
    id: '19408196',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'empty',
    private: false,
    updated_at: '2019-02-15T07:17:03Z' },
  { created_at: '2019-02-15T07:17:10Z',
    created_by_id: 'genie',
    id: '19408197',
    member_user_ids: [ 'genie' ],
    name: 'private',
    private: true,
    updated_at: '2019-02-15T07:17:10Z' } ] +300ms

because of #39 I also tried it both ways:

  static async status(userId = 'genie') {
    let allRooms = await Rabbit.chatkit.getRooms({})
    debug.info('all rooms=>', allRooms)

    Rabbit.chatkit.getRooms({})
      .then(allRooms => {
        debug.info('all rooms=>', allRooms)
      })
  }

Is there some weird options to the chatkit.getRooms({}) that somehow masks the users in that room?

FWIW I am connecting like this (in my own Class wrapper)
It seems to accept a userId like the client lib, but this does not have any effect.

  static async connect() {

    Rabbit.chatkit = await new Chatkit.default({
      instanceLocator: ChatkitConfig.INSTANCE_LOCATOR,
      // userId: userId,
      key: ChatkitConfig.SECRET_KEY
    })
    debug.info('init done')
  }

Basically seems that getRooms is not checking and lying on members, always null.
This is a simple bug to fix I guess.

Async / Promise behavior is unpredictable for basic queries

What?

I'm using the nodeJS lib, and having problems with promises not seeming to resolve when using async/await syntax

    let userRooms = await Rabbit.chatkit.getUserRooms({
      id: userId
    })
    debug.info('userRooms=>', userRooms) // [] empty

    let p = Rabbit.chatkit.getUserRooms({
      id: userId
    })
    debug.info('getUserRooms result=>', p) // Promise { <pending> } 
    p.then( info => {
      debug.info('p.then info', info) // [ ] still empty!
    })

    Rabbit.chatkit.getUserRooms({
      userId: userId
    }).then( (res, err) => {
      debug.info('userRooms p.res', res) // the only way this code works...
    })

only the final method will work

  Rabbit userRooms=> [] +302ms
  Rabbit getUserRooms result=> Promise { <pending> } +1ms
  Rabbit p.then info [] +309ms

  Rabbit userRooms p.res [ { created_at: '2019-01-28T06:31:30Z',
    created_by_id: 'dcsan',
    id: '19398582',
    member_user_ids: [ 'adminBot', 'dcsan', 'genie' ],
    name: 'lobby',
    private: false,
    updated_at: '2019-01-28T06:31:30Z' },
  { created_at: '2019-02-15T07:13:27Z',
    created_by_id: 'genie',
    id: '19408194',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'testing',
    private: false,
    updated_at: '2019-02-15T07:13:27Z' },
  { created_at: '2019-02-15T07:17:03Z',
    created_by_id: 'genie',
    id: '19408196',
    member_user_ids: [ 'dcsan', 'genie' ],
    name: 'empty',
    private: false,
    updated_at: '2019-02-15T07:17:03Z' } ] +9ms

Suggested improvements

I am getting an empty array [] as the result so it is not undefined ... but the array hasn't been populated before the Promise resolves, it seems, when using anything other than an inline .then()

Is there a way to get more expected behavior?
According to the node docs, each function should return a Promise, but even using p.then I can't get quite what I'm expecting. Perhaps this is related to the Promise itself being resolved, but the data isn't ready internally inside somehow from the socket? Really not clear

chatkit.getUsersByID is not a function

What?

I'm trying to get the individual user's data after a call to chatkit.getRoom. From that call I get the member_user_ids which I then supply as an argument to the chatkit.getUsersByID method.

Even supplying the user IDs directly (as the docs suggest) doesn't seem to work:

 const members = await chatkit.getUsersByID({
  userIds: [
    "193419644",
    "2087566530",
    "2087898568"
  ]
});

I'm using version 1.1.0 of @pusher/chatkit-server.

Add ability to turn notifications on and off on a specific room from Node JS server

What?

Add the ability to turn automatic sending of notifications for a room.

Suggested improvements

Thus when turned off, when a sendMessage is called either from the client or server it won't send a notification. We need this for a specific use case for our application and have gone to significant lengths to work around this limitation.

This could also be implemented as an option to sendMessage

client SDK and server SDK API differences

What?

I want to create a server based client (for a bot to listen to rooms)

with client code this works

    Rabbit.chatkit.getUser({
      id: userId,
    }).then(currentUser => {
      debug.info('connected currentUser', currentUser)
      let room = currentUser.rooms[0]

but server I have to call another API to get users list of rooms

Suggested improvements

normalize APIs / prepopulate room list on server response

sendSimpleMessage should accept SendSimpleMessageOptions

What?

At the moment sendSimpleMessage accepts SendMessageOptions, which takes an optional attachment: AttachmentOptions property.

This is incorrect for sending simple, text-only messages, and will appear as a suggestion in VSCode and other IDEs that support TS typings.

Suggested improvements

Create a new interface SendSimpleMessageOptions that doesn't include the attachment property.

how to subscribe from server SDK?

What?

I can't see any method from the current docs to subscribe to a room from the node/server SDK

tried based on client JS/SDK and get this:

TypeError: currentUser.subscribeToRoom is not a function
    at Rabbit.chatkit.getUserRooms.then (/Users/dc/dev/rikai/nap/web-app/server/routes/Rabbit.js:89:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)

When i try to use the client SDK it gives errors around window not defined. I guess someone hardcoded something in there.

Suggested improvements

How to get events on the server side from a room?

Getting 401 error while authenticating

const chatManager= new Chatkit.ChatManager({
instanceLocator:"v1:us1:xyz",
userId:"HK",
tokenProvider:new Chatkit.TokenProvider({
url:"http://localhost:8081/authenticate"
})
});
chatManager.connect().then((currentUser)=>{
console.log("current User",currentUser)})
.catch((error)=>{
console.error(error)})

while running the above code from the client

to the node/express server:-
app.post("/authenticate",(req,res)=>{
const {grant_type}=req.body;
res.json(chatkit.authenticate({grant_type,userId:req.query.user_id}));
});

throws an error:-

Logger.ERROR: error establishing presence subscription:
Could not parse the token. More information can be found at https://docs.pusher.com/errors/authentication/jwt/invalid. Error object:
{…}
headers: Object { "Request-Method": "SUBSCRIBE" }
info: {…}
error: "authentication/jwt/invalid"
error_description: "Could not parse the token"
error_uri: "https://docs.pusher.com/errors/authentication/jwt/invalid"
proto: Object { … }
statusCode: 401
proto: Object { … }

Can someone help me out fixing the
error chatkit
error.
Note:- I provided the correct "instanceLocator" in my application (not the one mentioned above)

Large file size

My apologies this is such a vague issue, and will be difficult to ‘resolve’, but would love to have a discussion about it.

I’m using Lambda functions to run the services for our app. We have an authorised route into the Lambda functions, and then they connect to ChatKit using this package as a Node.js app.

You probably already know, but in Lambda you have to upload 1 file with everything you need in it. So ideally, you want the file to be as lightweight as possible as you’re billed for usage.

I have an endpoint that creates a type of user in our app, and then once that’s confirmed, they are then also created on ChatKit. All the code I need for my user creation brings to the whole file up to 13.9 kB. (I appreciate that this is a very circumstantial place to be, but as an example), however when I add ChatKit (pusher-chatkit-server), this flies up to 2.18 MB.

Having looked through the dependancies, I think it could possibly be including typescript, which I know is quite large. I haven’t yet played around with switching to a production build as I know that’s only a dev dependancy.

My ‘issue’, per se, is that I’d love for the file size to be kept clean and simple. At the moment, I’m only using the createUser and authenticate functions, so it’s tempting for me to write my own functions for these two to shave off a few MB. As more people switch to more recent versions of Node, there’s less need for things like Babel and helpers to get around JavaScript’s lack of, well, lots of things.

As an aside, really loving ChatKit. It’s working really well for us and I’m excited to see where it goes.

Chatkit-Server not working (fs dependency missing)

What?

Chatkit-Server not working on a Gatsby Build with:
"@pusher/chatkit-client": "^1.5.0",
"@pusher/chatkit-server": "^1.3.0"

import Chatkit from '@pusher/chatkit-server'

const chatkit = new Chatkit({
instanceLocator: instanceLocator,
key: secretKey
})

 ERROR  Failed to compile with 2 errors                                                                                                 10:00:48 PM
⠀
This dependency was not found:
⠀
* fs in ./node_modules/@pusher/chatkit-server/node_modules/got/source/utils/get-body-size.js, ./node_modules/request/lib/har.js
⠀
To install it, you can run: npm install --save fs
error ✖ 「wdm」:
ERROR in ./node_modules/@pusher/chatkit-server/node_modules/got/source/utils/get-body-size.js
Module not found: Error: Can't resolve 'fs' in
'/Users/pie/Desktop/gatsby/wunschcoach-ssr/node_modules/@pusher/chatkit-server/node_modules/got/source/utils'
 @ ./node_modules/@pusher/chatkit-server/node_modules/got/source/utils/get-body-size.js 2:11-24
 @ ./node_modules/@pusher/chatkit-server/node_modules/got/source/request-as-event-emitter.js
 @ ./node_modules/@pusher/chatkit-server/node_modules/got/source/as-stream.js
 @ ./node_modules/@pusher/chatkit-server/node_modules/got/source/create.js
 @ ./node_modules/@pusher/chatkit-server/node_modules/got/source/index.js
 @ ./node_modules/@pusher/chatkit-server/target/src/chatkit.js
 @ ./node_modules/@pusher/chatkit-server/target/src/index.js
 @ ./src/chat/chatkit/chatkit.js
 @ ./src/components/molecules/ListItem/ListItemPendingContact.js
 @ ./src/components/pages/Private/ContactsPage.js
 @ ./src/gatsby/pages/app.js
 @ ./.cache/sync-requires.js
 @ ./.cache/app.js
 @ multi ./node_modules/event-source-polyfill/src/eventsource.js (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false
./.cache/app

ERROR in ./node_modules/request/lib/har.js
Module not found: Error: Can't resolve 'fs' in '/Users/pie/Desktop/gatsby/wunschcoach-ssr/node_modules/request/lib'
 @ ./node_modules/request/lib/har.js 3:9-22
 @ ./node_modules/request/request.js
 @ ./node_modules/request/index.js
 @ ./node_modules/@pusher/platform-node/target/base_client.js
 @ ./node_modules/@pusher/platform-node/target/index.js
 @ ./node_modules/@pusher/chatkit-server/target/src/index.js
 @ ./src/chat/chatkit/chatkit.js
 @ ./src/components/molecules/ListItem/ListItemPendingContact.js
 @ ./src/components/pages/Private/ContactsPage.js
 @ ./src/gatsby/pages/app.js
 @ ./.cache/sync-requires.js
info ℹ 「wdm」: Failed to compile.


Suggested improvements

default is not a constructor (with Babel): Error in docs

Just been trying this out today. From the examples, I was using this:

const chatkit = new Chatkit.default({
  instanceLocator: 'v1:us1:example',
  key: 'your:key'
});

However, this returns an error:

default is not a constructor

I’m using Babel, so my actual error is:

_pusherChatkitServer2.default.default is not a constructor

I changed my code to this (removing the .default):

const chatkit = new Chatkit({
  instanceLocator: 'v1:us1:example',
  key: 'your:key'
})

And it worked without error.

Enhancement Request: send notifications from Node JS via Chatkit to existing user

What?

We would like to send a notification to existing chatkit users of our app when they are invited to a new room using the Chatkit notification UI. We'd like these only to be sent if the user receiving the notification's app is not currently open and in the foreground on iOS or Android (just as is currently done with the room messages). We use channels to pop up an invitation dialog if the app is running in the foreground.

Currently we are tryin g using Beams but it does not seem to be compatible with Chatkit push notifications so we've had to turn Beams off and currently cannot send invitations in the form of push notifications.

Suggested improvements

sendMessage is not a function

What?

I looked through the source code and sendMessage is not a function, though it clearly says it is available in the documentation.

Suggested improvements

Can you please add support, or just remove it from the docs altogether.

Attempting to import the Node standard library module "url"

What?

I am trying to use the chatkit-server in a react-native app along with expo. During the dev running itself, i get the following compilation error:

The package at "node_modules/@pusher/platform-node/target/base_client.js" attempted to import the Node standard library module "url". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo

Can someone help me along with this?

Suggested improvements

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.