GithubHelp home page GithubHelp logo

isabella232 / chat-engine-push-notifications-payload Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pubnub/chat-engine-push-notifications-payload

0.0 0.0 0.0 34 KB

Home Page: https://www.pubnub.com/developers/chat-resource-center/

License: Other

JavaScript 100.00%

chat-engine-push-notifications-payload's Introduction

This repository is a part of the ChatEngine Framework. For more information on building chat applications with PubNub, see our Chat Resource Center.

Push Notifications Payload Plugin

Adds the ability to add to modify event payload with data, which is used to trigger remote push notifications.

Quick Start

  1. Have ChatEngine instantiated and connected, and have a chat you want to enable for push notification payload addition
const ChatEngine = ChatEngineCore.create({
    publishKey: 'pub-key-here',
    subscribeKey: 'sub-key-here',
});

ChatEngine.connect('uuid');
ChatEngine.on('$.ready', () => { ... });
  1. Attach this plugin to the chat you want, in this case global
let configuration = {
    events: ['message', 'ping'],
    formatter: (eventPayload) => ({
        apns: { aps: { alert: { title: 'Test title', body: 'Test body' } } },
        gcm: { data: { contentTitle: 'Test title', contentText: 'Test body', ticker: 'Testing' } } 
    })
};

/**
 * Call to 'plugin()' function on chat will register plugin only for that chat. 
 * 'global' is pre-defined chat, but can be any user-made chat.
 */
ChatEngine.global.plugin(ChatEngineCore.plugin['chat-engine-push-notifications-payload'](configuration));

/**
 * to register plugin for all created chats, place this line along with
 * configuration object before calling 'ChatEngine.connect()'.
 */
ChatEngine.proto('Chat', ChatEngineCore.plugin['chat-engine-push-notifications-payload'](configuration));
  1. If it is required to mark notifications for event as seen, following methods can be used
// Mark specific notification / event as seen.
ChatEngine.global.on('message', (payload) => {
    ChatEngine.global.notificationsPayload.markNotificationAsSeen(payload);
});
// Mark all notifications / event as seen.
ChatEngine.global.notificationsPayload.markAllNotificationAsSeen();
  1. Listen for the $notifications.seen events (on local user direct chat) to know, when this user seen notification for event on another device.
ChatEngine.me.direct.on('$notifications.seen', (payload) => {
    console.log(payload.data.eid, ' has been seen from another ChatEngine instance');
});

Support

  • If you need help, have a general question, have a feature request or to file a bug, contact [email protected].

chat-engine-push-notifications-payload's People

Contributors

crgbaumgart avatar madisonsmith avatar messagingmoore avatar parfeon 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.