@jinshuju/cli 0.21.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 +30 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/message.d.ts +2 -0
- package/dist/commands/message.js +174 -0
- package/dist/generated/operations.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -563,6 +563,36 @@ jinshuju email smtp-account list
|
|
|
563
563
|
jinshuju email send --form Kp7mQ2 --field field_3 --select-all --subject 上课提醒 --content '<p>明天上午 9 点开课</p>' --yes
|
|
564
564
|
```
|
|
565
565
|
|
|
566
|
+
## Sending one message
|
|
567
|
+
|
|
568
|
+
`message send` sends one message through a channel registered with the API: a
|
|
569
|
+
DingTalk or WeCom group robot, or a webhook, is the recipient itself; email and
|
|
570
|
+
SMS go to each `--to`, at most 50. `--mention` @s group members by mobile number,
|
|
571
|
+
or everyone with `@all`; WeCom sends a message that mentions anyone as plain
|
|
572
|
+
text, so leave Markdown out of it. SMS sends the channel's template: it takes
|
|
573
|
+
no `--title` or `--content`, and each of the template's variables comes as
|
|
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.
|
|
582
|
+
|
|
583
|
+
`message channel list` gives the ids `--channel` takes, `--type` narrowing
|
|
584
|
+
them, and `message channel get <id>` shows one. Email needs no channel: without
|
|
585
|
+
one it goes from Jinshuju's address and uses email quota; with one, through its
|
|
586
|
+
SMTP account.
|
|
587
|
+
|
|
588
|
+
```bash
|
|
589
|
+
jinshuju message channel list --type wxwork
|
|
590
|
+
jinshuju message send --type wxwork --channel 6729f1c2a1b2c3d4e5f60718 --content '今天是星期三,该吃午饭啦!' --mention 13800000000 --yes
|
|
591
|
+
jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes
|
|
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
|
|
594
|
+
```
|
|
595
|
+
|
|
566
596
|
## Artifacts
|
|
567
597
|
|
|
568
598
|
An artifact is a file Jiri made for you; any of your conversations can revise
|
package/dist/commands/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { FILL } from './fill.js';
|
|
|
18
18
|
import { FOLDER } from './folder.js';
|
|
19
19
|
import { FORM } from './form.js';
|
|
20
20
|
import { LOCAL } from './local.js';
|
|
21
|
+
import { MESSAGE } from './message.js';
|
|
21
22
|
import { NOTIFICATION } from './notification.js';
|
|
22
23
|
import { OPENSEARCH } from './opensearch.js';
|
|
23
24
|
import { ROUTINE } from './routine.js';
|
|
@@ -89,6 +90,10 @@ export const RESOURCES = [
|
|
|
89
90
|
{ name: 'payout', summary: 'Payouts to the settlement account' },
|
|
90
91
|
{ name: 'sms', summary: 'Manage SMS signatures and templates, and send SMS to entries' },
|
|
91
92
|
{ name: 'email', summary: 'Send email to entries' },
|
|
93
|
+
{
|
|
94
|
+
name: 'message',
|
|
95
|
+
summary: 'Send one message through a registered channel: group robots, webhooks, email and SMS; list the channels'
|
|
96
|
+
},
|
|
92
97
|
{
|
|
93
98
|
name: 'artifact',
|
|
94
99
|
summary: 'Artifacts Jiri made in a conversation: find and download them, and who can open an HTML one by its link',
|
|
@@ -115,6 +120,7 @@ export const COMMANDS = [
|
|
|
115
120
|
...TRADE,
|
|
116
121
|
...SMS,
|
|
117
122
|
...EMAIL,
|
|
123
|
+
...MESSAGE,
|
|
118
124
|
...ARTIFACT
|
|
119
125
|
];
|
|
120
126
|
/** The command whose path the words begin with, longest match first. */
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { UsageError } from '../errors.js';
|
|
2
|
+
import { PAGINATION_OPTIONS } from '../options.js';
|
|
3
|
+
import { call, choices } from '../spec.js';
|
|
4
|
+
import { given, LISTING, paging, requiredOption, SEND_OPTION } from './shared.js';
|
|
5
|
+
/** `var_1=张三`: one variable of an SMS channel's template. */
|
|
6
|
+
function parseVariable(input) {
|
|
7
|
+
const at = input.indexOf('=');
|
|
8
|
+
if (at <= 0)
|
|
9
|
+
throw new UsageError(`--variable must be '<name>=<value>', got ${JSON.stringify(input)}`);
|
|
10
|
+
return [input.slice(0, at), input.slice(at + 1)];
|
|
11
|
+
}
|
|
12
|
+
export const MESSAGE = [
|
|
13
|
+
{
|
|
14
|
+
path: ['message', 'send'],
|
|
15
|
+
summary: 'Send one message through a registered channel: a group robot or webhook, or email and SMS to --to',
|
|
16
|
+
description: 'Queues the message and answers at once with one record per recipient; a group robot or webhook is the ' +
|
|
17
|
+
'recipient itself. --mention is for DingTalk and WeCom robots only, at most 50; WeCom sends a message that ' +
|
|
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. 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 ' +
|
|
23
|
+
'or a dropped connection, send again with the same --idempotency-key, which answers the first records instead ' +
|
|
24
|
+
'of sending twice. --yes sends.',
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
name: '--type',
|
|
28
|
+
type: 'string',
|
|
29
|
+
choices: ['wxwork', 'ding_talk', 'webhook', 'email', 'sms'],
|
|
30
|
+
placeholder: '<type>',
|
|
31
|
+
description: 'wxwork, ding_talk, webhook, email or sms'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: '--channel',
|
|
35
|
+
type: 'string',
|
|
36
|
+
placeholder: '<id>',
|
|
37
|
+
description: 'Channel id, from `message channel list`. Required for a group robot, a webhook and SMS (an SMS channel sends ' +
|
|
38
|
+
"one template, once approved). Email may leave it out: it then goes from Jinshuju's address and uses the " +
|
|
39
|
+
"email quota; with one it goes through that channel's SMTP account"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: '--to',
|
|
43
|
+
type: 'string',
|
|
44
|
+
repeatable: true,
|
|
45
|
+
placeholder: '<recipient>',
|
|
46
|
+
description: 'Email address or mobile number for email and SMS, repeatable, at most 50'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: '--title',
|
|
50
|
+
type: 'string',
|
|
51
|
+
placeholder: '<text>',
|
|
52
|
+
description: 'Heading above the content, or the subject of an email'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: '--content',
|
|
56
|
+
type: 'string',
|
|
57
|
+
placeholder: '<text>',
|
|
58
|
+
description: "The message, in Markdown unless it mentions anyone on WeCom; an email's becomes HTML and takes up to " +
|
|
59
|
+
'20,000 characters'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: '--variable',
|
|
63
|
+
type: 'string',
|
|
64
|
+
repeatable: true,
|
|
65
|
+
placeholder: '<name>=<value>',
|
|
66
|
+
description: "Every variable the SMS channel's template declares, as it is named there (var_1...), each 1 to 100 " +
|
|
67
|
+
'characters; repeatable'
|
|
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
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: '--mention',
|
|
91
|
+
type: 'string',
|
|
92
|
+
repeatable: true,
|
|
93
|
+
placeholder: '<mobile|@all>',
|
|
94
|
+
description: 'Group member to @ by mobile number, or @all for everyone; repeatable'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: '--idempotency-key',
|
|
98
|
+
type: 'string',
|
|
99
|
+
placeholder: '<key>',
|
|
100
|
+
description: 'Sends once for the same key within 24 hours; retry with the same key'
|
|
101
|
+
},
|
|
102
|
+
SEND_OPTION
|
|
103
|
+
],
|
|
104
|
+
request: (input) => {
|
|
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
|
+
}
|
|
117
|
+
if (!input.options.yes)
|
|
118
|
+
throw new UsageError('A sent message cannot be recalled; pass --yes to send');
|
|
119
|
+
const variables = input.options.variable;
|
|
120
|
+
return call('sendMessage', {
|
|
121
|
+
body: given({
|
|
122
|
+
type,
|
|
123
|
+
channel_id: input.options.channel,
|
|
124
|
+
to: input.options.to,
|
|
125
|
+
title: input.options.title,
|
|
126
|
+
content: input.options.content,
|
|
127
|
+
variables: variables && Object.fromEntries(variables.map(parseVariable)),
|
|
128
|
+
mentioned_mobile_list: input.options.mention,
|
|
129
|
+
body,
|
|
130
|
+
form_token: input.options.form,
|
|
131
|
+
entries: input.options.entry,
|
|
132
|
+
idempotency_key: input.options.idempotency_key
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
examples: [
|
|
137
|
+
"jinshuju message send --type wxwork --channel 6729f1c2a1b2c3d4e5f60718 --content '今天是星期三,该吃午饭啦!' " +
|
|
138
|
+
'--mention 13800000000 --yes',
|
|
139
|
+
"jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes",
|
|
140
|
+
'jinshuju message send --type sms --channel 6729f1c2a1b2c3d4e5f60719 --to 13800000000 --variable var_1=张三 ' +
|
|
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'
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
path: ['message', 'channel', 'list'],
|
|
149
|
+
summary: 'List the channels `message send` can send through, newest first',
|
|
150
|
+
description: 'The channels you registered, or every channel of the account for an account access token. The id goes to ' +
|
|
151
|
+
'`message send --channel`. address is the robot or webhook address with its key hidden, empty for email and ' +
|
|
152
|
+
'SMS; an email channel carries its smtp_account_id and an SMS one its sms_template_id.',
|
|
153
|
+
options: [
|
|
154
|
+
{
|
|
155
|
+
name: '--type',
|
|
156
|
+
type: 'string',
|
|
157
|
+
choices: choices('listMessageChannels', 'type'),
|
|
158
|
+
placeholder: '<type>',
|
|
159
|
+
description: 'Only the channels of this type: wxwork, ding_talk, webhook, email or sms'
|
|
160
|
+
},
|
|
161
|
+
...PAGINATION_OPTIONS
|
|
162
|
+
],
|
|
163
|
+
request: (input) => call('listMessageChannels', { query: { type: input.options.type, ...paging(input) } }),
|
|
164
|
+
paginate: LISTING,
|
|
165
|
+
examples: ['jinshuju message channel list', 'jinshuju message channel list --type sms']
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
path: ['message', 'channel', 'get'],
|
|
169
|
+
summary: 'Show a channel `message send` can send through',
|
|
170
|
+
args: [{ name: 'id', required: true, description: 'Channel id, from `message channel list`' }],
|
|
171
|
+
request: (input) => call('getMessageChannel', { path: { id: input.args.id } }),
|
|
172
|
+
examples: ['jinshuju message channel get 6729f1c2a1b2c3d4e5f60718']
|
|
173
|
+
}
|
|
174
|
+
];
|
|
@@ -5738,12 +5738,15 @@ export const SCHEMAS = {
|
|
|
5738
5738
|
WebhookMessageInput: {
|
|
5739
5739
|
type: 'object',
|
|
5740
5740
|
additionalProperties: false,
|
|
5741
|
-
required: ['type', 'channel_id'
|
|
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
|
},
|