https://github.com/xizhibei/getui-rest-sdk
The Node.js sdk for Getui, based on rest api
https://github.com/xizhibei/getui-rest-sdk
getui getui-nodejs getui-rest-sdk getui-sdk message node-js nodejs nodejs-modules push-notifications rest-api sdk sdk-nodejs typescript
Last synced: 7 months ago
JSON representation
The Node.js sdk for Getui, based on rest api
- Host: GitHub
- URL: https://github.com/xizhibei/getui-rest-sdk
- Owner: xizhibei
- License: mit
- Created: 2017-12-20T13:46:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T21:47:41.000Z (over 3 years ago)
- Last Synced: 2025-02-12T22:37:42.189Z (over 1 year ago)
- Topics: getui, getui-nodejs, getui-rest-sdk, getui-sdk, message, node-js, nodejs, nodejs-modules, push-notifications, rest-api, sdk, sdk-nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 445 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 13
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Getui Rest SDK

[](http://badge.fury.io/js/getui-rest-sdk)
[](https://david-dm.org/xizhibei/getui-rest-sdk)
[](https://github.com/xizhibei/getui-rest-sdk/blob/master/LICENSE)
[](https://greenkeeper.io/)
### Getting Started
详细原接口文档:http://docs.getui.com/server/rest/start/
> 除了原文档中的接口,其中另外还提供了 `pushMessageByTag` 方法,可以用来发送按 tag 或者说按 topic 方式推送数据。
### Installing
```bash
npm i @xizhibei/getui-rest-sdk --save
```
建议使用 vscode 开发,typing 代码提示更加完善
### Usage
以下样例均使用 TypeScript 展示,可轻易修改为 ES6
##### 初始化
```ts
const option: GetuiOption = {
appId: APP_ID,
appSecret: APP_SECRET,
appKey: APP_KEY,
masterSecret: MASTER_SECRET,
};
const gt = new Getui(option);
```
##### 初始化透传模板
```ts
const alert = new Alert();
alert.title = 'Title: push test';
alert.body = `Body: push test`;
const payload = JSON.stringify({
message: `Payload message: push message test`,
});
const apnsInfo = new ApnsInfo();
apnsInfo.alert = alert;
apnsInfo.customMsg = { payload };
const template = new TransmissionTemplate();
template.transmissionContent = payload;
```
##### 单个推送
```ts
const message = new SingleMessage();
message.template = template;
message.apnsInfo = apnsInfo;
const target = {
cid: GETUI_CID,
};
const ret = await gt.pushMessageToSingle(message, target);
```
##### APP推送
```ts
const message = new AppMessage();
message.template = template;
message.apnsInfo = apnsInfo;
message.conditions = [
new Condition(ConditionKey.TAG, [testTag], CondOptType.OR),
new Condition(ConditionKey.Region, [Region.北京市], CondOptType.OR),
new Condition(ConditionKey.PHONE_TYPE, [PhoneType.IOS], CondOptType.OR),
];
const ret = await gt.pushMessageToApp(message)
```
##### 按 tag 推送
```ts
const message = new TagMessage();
message.template = template;
message.apnsInfo = apnsInfo;
message.tag = testTag;
const ret = await gt.pushMessageByTag(message);
```
更多样例,请见测试代码
### Test
测试基于 nock 来模拟服务器,但是你可以设置环境变量与真实个推服务器测试进行交互,以下测试账号数据需要用你自己的
```bash
export GETUI_APP_ID=
export GETUI_APP_SECRET=
export GETUI_APP_KEY=
export GETUI_MASTER_SECRET=
export GETUI_CID=
export GETUI_TEST_TAG=
export GETUI_TEST_USE_REAL_CONNECTION=true
export DEBUG=getui
npm test
```
### TODO
- 测试代码完善
### License
This project is licensed under the MIT License - see the LICENSE file for details