Giter VIP home page Giter VIP logo

mns-nodejs-sdk's Introduction

mns-nodejs-sdk

NPM version build status coverage

Documents: http://doxmate.cool/aliyun/mns-nodejs-sdk/api.html

该 SDK 并未完全实现所有文档所提及的功能,如果您想使用的功能并未实现,请提issue以增加优先级。

Installation

npm install @alicloud/mns --save

API Spec

See: https://help.aliyun.com/document_detail/27475.html

Test

ACCOUNT_ID=<ACCOUNT_ID> ACCESS_KEY_ID=<ACCESS_KEY_ID> ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET> make test

Installation

You can install it via npm/cnpm/yarn.

$ npm install @alicloud/mns --save

Usage

const MNSClient = require('@alicloud/mns');

const accountid = '<account id>';
var client = new MNSClient(accountid, {
  region: '<region>',
  accessKeyId: '<access key id>',
  accessKeySecret: '<access key secret>',
  // optional & default
  secure: false, // use https or http
  internal: false, // use internal endpoint
  vpc: false // use vpc endpoint
});

(async function () {
  let res;
  // create queue
  res = await client.createQueue('test-queue2');
  console.log(res);
  // list queue
  res = await client.listQueue();
  console.log(JSON.stringify(res, null, 2));
  // create topic
  res = await client.createTopic('test-topic');
  console.log(res);
  // get topic attributes
  res = await client.getTopicAttributes('test-topic');
  console.log(res);
  // publish message
  res = await client.publishMessage('<topic name>', {
    MessageBody: 'content',
    MessageAttributes: {
      DirectSMS: JSON.stringify({
        FreeSignName: '',
        TemplateCode: '<template code>',
        Type: '<type>',
        Receiver: '<phone number>',
        SmsParams: JSON.stringify({
          code: '<code>',
          product: '<product>'
        })
      })
    }
  });
  console.log(res);
})().then((data) => {
  console.log(data);
}, (err) => {
  console.log(err.stack);
});

License

The MIT License

mns-nodejs-sdk's People

Contributors

hybrid-force avatar jacksontian avatar paolomainardi avatar ql434 avatar wirabdillah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mns-nodejs-sdk's Issues

Enhancement - sendMessage

Currently, sendMessage only requires two arguments, queueName is make sense but params is a little confusion without example. one more point is building the object(arguement 'params' requires) is not friendly for developers.
Therefore, suggest to put the attributes of the params as arguments in method.

take an example, enhanced can be like below:

sendMessage(queueName, messageBody, delaySeconds=0, priority=1){
const url = /queues/${queueName}/messages;
const body = toXMLBuffer('Message', {
MessageBody: messageBody,
DelaySeconds: delaySeconds,
Priority: priority
});
return this.post(url, 'Message', body);
}

PS.

current logic: sendMessage(queueName, params)

{
const url = /queues/${queueName}/messages;
const body = toXMLBuffer('Message', params);
return this.post(url, 'Message', body);
}

params so far required example:

{
MessageBody: message,
DelaySeconds: delaySeconds,
Priority: priority
}

Response body with content-type application/xml is not parsed

I'm running against MNS in ap-southeast-2 region. Requests are returning success but no body is returned. While debugging it seems the response content-type is application/xml but the code is expecting text/xml.

e.g. Changing this line starts working for me:

if (responseBody && contentType.startsWith('text/xml')) {

to

if (responseBody && contentType.startsWith('application/xml')) {

Unexpected identifier

引入库@alicloud/sms-sdk,直接就报错了,帮忙看一下,谢谢

async _getMNSClient(type) {
^^^^^^^^^^^^^
SyntaxError: Unexpected identifier

batchDeleteMessage not work

请帮忙看下batchDeleteMessage接口是否有bug 或者是我传的参数格式不正确?

Got below errors when I was trying to do batch delete

DELETE http://1293562333402418.mns.cn-hangzhou.aliyuncs.com/queues/sync-queue-3w-test/messages failed with 400. requestid: 5AD846B6027AA042745F56DB, hostid: http://1293562333402418.mns.cn-hangzhou.aliyuncs.com, message: The XML you provided was not well-formed.
MNSMalformedXMLError

Params I used:

[ { ReceiptHandle: '1-ODU4OTkzNDU5My0xNTI0MTIzMzQ4LTEtOA==' },
  { ReceiptHandle: '1-ODU4OTkzNDU5NC0xNTI0MTIzMzQ4LTEtOA==' },
  { ReceiptHandle: '1-ODU4OTkzNDU5NS0xNTI0MTIzMzQ4LTEtOA==' } ]

Is it a bug in code or just the params I passed to the API was in wrong format?

MNSMalformedXMLError failed with 400

const payload = {
    "title":{
            "en":"</3"
    },
    "name": "black&red"
}

await mnsClient.sendMessage(MNS_QUEUE_NAME, {
            MessageBody: JSON.stringify(payload)
});

some special character like '&' . occur error

SyntaxError: Unexpected token )

https://github.com/aliyun/mns-nodejs-sdk/blob/master/lib/client.js#L259

node version 7.x

/home/xxx/node_modules/@alicloud/mns/lib/client.js:252
    const response = await this.delete(`/queues/${queueName}/messages`, 'Errors', body, );
                                                                                        ^
SyntaxError: Unexpected token )
    at createScript (vm.js:53:10)
    at Object.runInThisContext (vm.js:95:10)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/airdwing/projects/AirX/node_modules/@alicloud/mns/index.js:3:18)

on 8.0 after ok.

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.