@jinshuju/cli 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -571,9 +571,14 @@ SMS go to each `--to`, at most 50. `--mention` @s group members by mobile number
571
571
  or everyone with `@all`; WeCom sends a message that mentions anyone as plain
572
572
  text, so leave Markdown out of it. SMS sends the channel's template: it takes
573
573
  no `--title` or `--content`, and each of the template's variables comes as
574
- `--variable <name>=<value>`. A sent message cannot be recalled, so it
575
- takes `--yes`. After a timeout, send again with the same `--idempotency-key`:
576
- the API answers the first records instead of sending twice.
574
+ `--variable <name>=<value>`. From Jiri, a webhook can push entries of a form or
575
+ table instead of a title and content: `--form` names it and each `--entry` a
576
+ serial number, at most 50, each entry in a request of its own shaped as a form
577
+ webhook notification pushes it. A webhook can also push JSON of your own
578
+ instead: `--body` is the whole request body, the text of a JSON object or
579
+ array, posted as it is. A sent message cannot be recalled, so it takes
580
+ `--yes`. After a timeout, send again with the same `--idempotency-key`: the
581
+ API answers the first records instead of sending twice.
577
582
 
578
583
  `message channel list` gives the ids `--channel` takes, `--type` narrowing
579
584
  them, and `message channel get <id>` shows one. Email needs no channel: without
@@ -585,6 +590,7 @@ jinshuju message channel list --type wxwork
585
590
  jinshuju message send --type wxwork --channel 6729f1c2a1b2c3d4e5f60718 --content '今天是星期三,该吃午饭啦!' --mention 13800000000 --yes
586
591
  jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes
587
592
  jinshuju message send --type sms --channel 6729f1c2a1b2c3d4e5f60719 --to 13800000000 --variable var_1=张三 --variable var_2=9:00 --yes
593
+ jinshuju message send --type webhook --channel 6729f1c2a1b2c3d4e5f6071a --body '{"report":"orders","order_count":1}' --yes
588
594
  ```
589
595
 
590
596
  ## Artifacts
@@ -16,7 +16,10 @@ export const MESSAGE = [
16
16
  description: 'Queues the message and answers at once with one record per recipient; a group robot or webhook is the ' +
17
17
  'recipient itself. --mention is for DingTalk and WeCom robots only, at most 50; WeCom sends a message that ' +
18
18
  "mentions anyone as plain text, so leave Markdown out of it. SMS sends the channel's template, so it takes no " +
19
- '--title or --content: give each of its variables with --variable. Sent messages cannot be recalled: after a timeout ' +
19
+ '--title or --content: give each of its variables with --variable. From Jiri, a webhook can push entries of a ' +
20
+ 'form or table instead of --title and --content: --form names it and --entry each serial number, each entry in a ' +
21
+ 'request of its own, shaped as a form webhook notification pushes it. A webhook can also push JSON of your own ' +
22
+ 'instead: --body is the whole request body, posted as it is. Sent messages cannot be recalled: after a timeout ' +
20
23
  'or a dropped connection, send again with the same --idempotency-key, which answers the first records instead ' +
21
24
  'of sending twice. --yes sends.',
22
25
  options: [
@@ -63,6 +66,26 @@ export const MESSAGE = [
63
66
  description: "Every variable the SMS channel's template declares, as it is named there (var_1...), each 1 to 100 " +
64
67
  'characters; repeatable'
65
68
  },
69
+ {
70
+ name: '--body',
71
+ type: 'string',
72
+ placeholder: '<json>',
73
+ description: 'For a webhook, in place of --title and --content: the whole request body, the text of a JSON object or ' +
74
+ 'array, at most 65536 bytes, posted as it is'
75
+ },
76
+ {
77
+ name: '--form',
78
+ type: 'string',
79
+ placeholder: '<token>',
80
+ description: 'Only from Jiri, for a webhook: the form or table whose entries --entry names'
81
+ },
82
+ {
83
+ name: '--entry',
84
+ type: 'integer',
85
+ repeatable: true,
86
+ placeholder: '<serial_number>',
87
+ description: 'Only from Jiri, for a webhook with --form: the serial number of an entry to push, repeatable, at most 50'
88
+ },
66
89
  {
67
90
  name: '--mention',
68
91
  type: 'string',
@@ -80,6 +103,17 @@ export const MESSAGE = [
80
103
  ],
81
104
  request: (input) => {
82
105
  const type = requiredOption(input, 'type');
106
+ const body = input.options.body;
107
+ if (body !== undefined) {
108
+ if (type !== 'webhook')
109
+ throw new UsageError(`--body is for --type webhook only, not ${type}`);
110
+ for (const flag of ['title', 'content', 'form', 'entry']) {
111
+ const value = input.options[flag];
112
+ if (Array.isArray(value) ? value.length > 0 : value !== undefined) {
113
+ throw new UsageError(`--${flag} cannot be combined with --body: the body is the whole request`);
114
+ }
115
+ }
116
+ }
83
117
  if (!input.options.yes)
84
118
  throw new UsageError('A sent message cannot be recalled; pass --yes to send');
85
119
  const variables = input.options.variable;
@@ -92,6 +126,9 @@ export const MESSAGE = [
92
126
  content: input.options.content,
93
127
  variables: variables && Object.fromEntries(variables.map(parseVariable)),
94
128
  mentioned_mobile_list: input.options.mention,
129
+ body,
130
+ form_token: input.options.form,
131
+ entries: input.options.entry,
95
132
  idempotency_key: input.options.idempotency_key
96
133
  })
97
134
  });
@@ -101,7 +138,10 @@ export const MESSAGE = [
101
138
  '--mention 13800000000 --yes',
102
139
  "jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes",
103
140
  'jinshuju message send --type sms --channel 6729f1c2a1b2c3d4e5f60719 --to 13800000000 --variable var_1=张三 ' +
104
- '--variable var_2=9:00 --yes'
141
+ '--variable var_2=9:00 --yes',
142
+ 'jinshuju message send --type webhook --channel 6729f1c2a1b2c3d4e5f6071a --form Kp7mQ2 --entry 1282 --entry 1283 --yes',
143
+ 'jinshuju message send --type webhook --channel 6729f1c2a1b2c3d4e5f6071a ' +
144
+ '--body \'{"report":"orders","order_count":1}\' --yes'
105
145
  ]
106
146
  },
107
147
  {
@@ -5738,12 +5738,15 @@ export const SCHEMAS = {
5738
5738
  WebhookMessageInput: {
5739
5739
  type: 'object',
5740
5740
  additionalProperties: false,
5741
- required: ['type', 'channel_id', 'content'],
5741
+ required: ['type', 'channel_id'],
5742
5742
  properties: {
5743
5743
  type: { type: 'string', enum: ['webhook'] },
5744
5744
  channel_id: { type: 'string' },
5745
5745
  title: { type: 'string', maxLength: 200 },
5746
5746
  content: { type: 'string' },
5747
+ body: { type: 'string' },
5748
+ form_token: { type: 'string' },
5749
+ entries: { type: 'array', minItems: 1, maxItems: 50, uniqueItems: true, items: { type: 'integer' } },
5747
5750
  idempotency_key: { type: 'string', maxLength: 255 }
5748
5751
  }
5749
5752
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {