Socket
Socket
Sign inDemoInstall

hcm-admin

Package Overview
Dependencies
2
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

hcm-admin


Version published
Weekly downloads
25
decreased by-89.84%
Maintainers
0
Created
Weekly downloads
 

Readme

Source

HMS Core Push Kit (Node.js)

English | 中文

Contents

Introduction

The sample code for Node.js encapsulates the server-side APIs of Push Kit, for your reference or direct use.

The following table describes packages of Node.js sample code.

PackageDescription
examplesSample code packages.
utilsPackage that provides methods for sending public network requests and for common verification.
pushPackage where Push Kit server APIs are encapsulated.

Installation

Install Node.js on your device.

Run the following command in the nodejs-sdk project:

$ npm install

Run the following command:

$ npm run build

Environment Requirements

Node.js 8.13.0 or later.

Note that the Node.js sample code can be used only in the server-side or background environments that you control, including most servers and serverless platforms (both on-premise and in the cloud).

Configuration

Start configuration with the index.ts file. Create an HcmNamespace object, and call the methods in the object to perform initialization. Access different modules, such as the messaging or topic module, and call the methods in each module.

To use the functions provided by the packages in examples, set initialization and request parameters in the config.js file.

ParameterDescription
AppIdApp ID, which is obtained from the app information.
AppSecretApp secret, which is obtained from the app information.
AuthUrlURL for Huawei OAuth 2.0 to obtain a token. For details, please refer to OAuth 2.0-based Authentication.
PushUrlAccess address of Push Kit. For details, please refer to Downlink Message Sending.
Request ParameterDescription
TargetTopicName of the topic to be subscribed to, unsubscribed from, or queried.
TargetConditionCombined condition expression for sending a message.
TargetTokenToken of a target device.

Sample Code

node.js sample code uses index.ts as the entry. Call methods on object HcmNamespace: messaging and topic.

The following table lists methods in HcmNamespace.

MethodDescription
messagingThe entry of the Messaging object, and verify the initialization input parameters.
topicThe entry of the Topic object, and verify the initialization input parameters.

The following table lists methods in Messaging.

MethodDescription
sendVerify if the token needs to be updated and call the method sendRequest.
sendRequestSends a message to a device.

The following table lists methods in Topic.

MethodDescription
subScribeTopicSubscribe to topic.
unSubScribeTopicUnsubscribe topic.
queryTopicListQuery subject list.
1. Send an Android data message.

Code location: examples/send_data_message.js

2. Send an Android notification message.

Code location: examples/send_notify_message.js

3. Send a message by topic.

Code location: examples/send_topic_message.js

4. Send a message by conditions.

Code location: examples/send_condition_message.js

5. Send a message to a Huawei quick app.

Code location: examples/send_instance_app_message.js

6. Send a message through the WebPush agent.

Code location: examples/send_webpush_message.js

7. Send a message through the APNs agent.

Code location: examples/send_apns_message.js

8. Send a test message.

Code location: examples/send_test_message.js

Technical Support

You can visit the Reddit community to obtain the latest information about HMS Core and communicate with other developers.

If you have any questions about the sample code, try the following:

  • Visit Stack Overflow, submit your questions, and tag them with huawei-mobile-services. Huawei experts will answer your questions.
  • Visit the HMS Core section in the HUAWEI Developer Forum and communicate with other developers.

If you encounter any issues when using the sample code, submit your issues or submit a pull request.

License

The sample code is licensed under Apache License 2.0.

Keywords

FAQs

Last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc