diff --git a/README.md b/README.md index fd2f832..32b3171 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ new Tmc('your_app_key', 'your_app_secret') **`tmc.send(msg: Message, options?: { mask?: true, binary?: true }, cb?: (err: Error) => void) => void`** -实例化后,当自动应答确认消息无法满足需求的时候,比如消息处理失败,需要`Publisher`再次重推消息,在实例初始化时置`options.autoReplyConfirmation=false`,则在消息处理函数内,可以通过 `this.send()` 函数回复`确认`或者`失败`消息。例如: +自`v0.3.4`起,当自动应答确认消息无法满足需求的时候,比如消息处理失败,需要`Publisher`再次重推消息,在实例初始化时置`options.autoReplyConfirmation=false`,则在消息处理函数内,可以通过 `this.send()` 函数回复`确认`或者`失败`消息。例如: ```js new Tmc('your_app_key', 'your_app_secret', { autoReplyConfirmation: false }) @@ -91,6 +91,29 @@ new Tmc('your_app_key', 'your_app_secret', { autoReplyConfirmation: false }) .connect(); ``` +也可以使用此方法发送`To淘宝`消息,`>=v0.3.4 && =v0.3.4 && 可选设置的 NODE_DEBUG=< label > 环境变量 | label | 说明 | diff --git a/lib/consumer.js b/lib/consumer.js index 3eea893..e6fe7f6 100644 --- a/lib/consumer.js +++ b/lib/consumer.js @@ -99,10 +99,16 @@ class TaoMessageConsumer extends EventEmitter { * @param {object|Function} [options] - The options * @param {Function} [cb] - The Callback * @returns {void} - * @since v0.3.4 + * @since v0.3.4 Exposed for `send(new Message(SENDACK, Failed))` scene + * @since v0.3.7 The `data.content.content` can be a plain `object` now */ send(data, options = { mask: true, binary: true }, cb = undefined) { - if (data instanceof Message) { this[kWebSocket]?.send(data.with(TOKEN, this[kToken]).buffer, options, cb); } + if (data instanceof Message) { + if (typeof data[CONTENT][CONTENT] === 'object' && data[CONTENT][CONTENT] !== null) { + Reflect.set(data[CONTENT], CONTENT, stringify(data[CONTENT][CONTENT])); + } + this[kWebSocket]?.send(data.with(TOKEN, this[kToken]).buffer, options, cb); + } } onopen() { diff --git a/package.json b/package.json index 02a2764..1d771c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tmc.js", - "version": "0.3.6", + "version": "0.3.7", "description": "Events driven and chained Taobao Message Channel(TMC) for NodeJS", "author": "James ZHANG", "license": "MIT",