npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alfredkoncsag/hms-push

v1.2.1

Published

HMS push service SDK.

Downloads

72

Readme

HMS Pushkit

Table of Contents

Installation

$ npm install --save @alfredkoncsag/hms-push

Configuration

Before using functions provided by packages in examples, you need to set parameters for initialization in config.js.

| Initialization Parameter | Description | | ---- | ----- | | AppId|App ID, which is obtained from app information. | | AppSecret|Secret access key of an app, which is obtained from app information. | | AuthUrl|URL for the Huawei OAuth 2.0 service to obtain a token, please refer to Generating an App-Level Access Token. | | PushUrl|URL for accessing HUAWEI Push Kit, please refer to Sending Messages. |

| Request Parameter | Description | | ---- | ----- | | TargetTopic|Name of a topic to be subscribed to, unsubscribed from, or queried. | | TargetCondition|Combination of condition expressions for a message. | | TargetToken|Token of a destination device. | | TargetTokenArray|Tokens of destination devices. |

Examples

Call methods on object HmsNamespace: messaging and topic.

The following table lists methods in HmsNamespace. | Method | Description | | ---- | ---- | | messaging | The entry of the Messaging object, and verify the initialization input parameters. | | topic | The entry of the Topic object, and verify the initialization input parameters. |

The following table lists methods in Messaging. | Method | Description | | ---- | ---- | | send | Verify if the token needs to be updated and call the method sendRequest. | | sendRequest | Sends a message to a device. |

The following table lists methods in Topic. | Method | Description | | ---- | ---- | | subScribeTopic | Subscribe to topic. | | unSubScribeTopic | Unsubscribe topic. | | queryTopicList | Query subject list. |


1. Send data message.

const hms = require("@alfredkoncsag/hms-push").default;
const config = require("./config");

hms.init({
    appId: config.AppId,
    appSecret: config.AppSecret,
    authUrl: config.AuthUrl,
    pushUrl: config.PushUrl
});

let mc = hms.messaging().messaging;

let AndroidConfig = {
    collapse_key: -1,
    urgency: "HIGH",
    ttl: "10000s",
    bi_tag: "the_sample_bi_tag_for_receipt_service"
}
let message = {
    data: "test",
    android: AndroidConfig,
    token: config.AndroidTokenArray
            
};    
mc.send(message, false).then(data => {
    console.log(data);
}).catch(err => {
    console.log(err);
});

1. Send Test message.

const hcm = require("@alfredkoncsag/hms-push").default;
const config = require("./config");

hcm.init({
    appId: config.AppId,
    appSecret: config.AppSecret,
    authUrl: config.AuthUrl,
    pushUrl: config.PushUrl
});

let mc = hcm.messaging().messaging;

let notification = {
    title: "Test title",
    body: "Test body"
}
let androidNotification = {
    icon: '... .png',
    color: '#AACCDD',
    sound: '... .mp3',
    default_sound: true,
    tag: 'tagBoom',
    click_action: {
        type: 1,
        intent:"intent"
    },
    body_loc_key: 'M.String.body',
    body_loc_args: ['boy', 'dog'],
    title_loc_key: 'RingRing',
    title_loc_args: ["Girl", "Cat"],
    channel_id: 'Your Channel ID',
    notify_summary: 'some summary',
    multi_lang_key: {        
        title_key: {            
            en: "Foo Bar",            
            zh: "Foo Bar",            
            ru: "Foo Bar"        
        },        
        body_key: {            
            en: "My name is %s, I am from %s.",            
            zh: "My name is %s, I am from %s.",            
            ru: "My name is %s, I am from %s."        
        }
    },
    style: 1,
    big_title: 'test message',
    big_body: 'Big Boom Body',
    auto_clear: 86400000,
    notify_id: 486,
    group: 'Group1',
    importance: "HIGH",
    light_settings: {
        color: {
            alpha:0, red:0, green:1, blue:1
        }, 
        light_on_duration: "3.5", 
        light_off_duration: "5S"
    },
    badge:{
        add_num:99,
        set_num:99,
        class:"Classic"
    },
    ticker:"i am a ticker",
    auto_cancel:false,
    when:"2019-11-05",
    use_default_vibrate:true,
    use_default_light:false,
    visibility: 'PUBLIC',
    vibrate_config:[
        "1.5",
        "2.000000001",
        "3"
    ],
    foreground_show:true
}
let androidConfig = {
    collapse_key: -1,
    urgency:"HIGH",
    ttl: "10000s",
    bi_tag: "the_sample_bi_tag_for_receipt_service",
    notification: androidNotification
}
let message = {
    data:"{key1:value1}",
    notification: notification,
    android: androidConfig,
    token: config.AndroidTokenArray
            
};    

mc.send(message, false).then(data => {
    console.log(data);
}).catch(err => {
    console.log(err);
});

2. Send data message.

const hms = require("@alfredkoncsag/hms-push").default;
const config = require("./config");

hms.init({
    appId: config.AppId,
    appSecret: config.AppSecret,
    authUrl: config.AuthUrl,
    pushUrl: config.PushUrl
});

let mc = hms.messaging().messaging;

let AndroidConfig = {
    collapse_key: -1,
    urgency: "HIGH",
    ttl: "10000s",
    bi_tag: "the_sample_bi_tag_for_receipt_service"
}
let message = {
    data: "test",
    android: AndroidConfig,
    token: config.AndroidTokenArray
            
};    
mc.send(message, false).then(data => {
    console.log(data);
}).catch(err => {
    console.log(err);
});

License

HMS Pushkit is licensed under the Apache License, version 2.0.