Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
elquimeras committed May 7, 2021
1 parent 8edca2e commit 2e143d5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
# hcm-node

Node.js package code encapsulates APIs of the HUAWEI Push Kit server.

## Installation

```bash
$ npm i hcm-node
```

## Usage

```typescript
import HCM from 'hcm-node';
import { Messaging } from 'hcm-node/dist/push/messaging';

const hcm = new HCM();
hcm.init({
appId: '<YOUR-APP-ID>',
appSecret: '<YOUR-APP-SECRET>',
authUrl: 'https://oauth-login.cloud.huawei.com/oauth2/v2/token',
pushUrl: 'https://push-api.cloud.huawei.com/v1'
);
const hcmDispatcher = hcm.messaging().messaging;

try {
const response = hcmDispatcher.send(message, false);

/**
* HCM Response code for success = 80000000
* more info @ https://developer.huawei.com/consumer/en/doc/development/HMS-References/push-sendapi
*/
if (response.code != '80000000') {
throwError(response);
}
} catch(error) {
throwError(error);
}

function throwError(detail: any): void {
console.error({
message: 'push notification dispatch failed',
details: error,
});

throw new Error('External error');
}

```

0 comments on commit 2e143d5

Please sign in to comment.