@jinshuju/cli 0.21.0 → 0.22.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 +24 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/message.d.ts +2 -0
- package/dist/commands/message.js +134 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -563,6 +563,30 @@ 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>`. 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.
|
|
577
|
+
|
|
578
|
+
`message channel list` gives the ids `--channel` takes, `--type` narrowing
|
|
579
|
+
them, and `message channel get <id>` shows one. Email needs no channel: without
|
|
580
|
+
one it goes from Jinshuju's address and uses email quota; with one, through its
|
|
581
|
+
SMTP account.
|
|
582
|
+
|
|
583
|
+
```bash
|
|
584
|
+
jinshuju message channel list --type wxwork
|
|
585
|
+
jinshuju message send --type wxwork --channel 6729f1c2a1b2c3d4e5f60718 --content '今天是星期三,该吃午饭啦!' --mention 13800000000 --yes
|
|
586
|
+
jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes
|
|
587
|
+
jinshuju message send --type sms --channel 6729f1c2a1b2c3d4e5f60719 --to 13800000000 --variable var_1=张三 --variable var_2=9:00 --yes
|
|
588
|
+
```
|
|
589
|
+
|
|
566
590
|
## Artifacts
|
|
567
591
|
|
|
568
592
|
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,134 @@
|
|
|
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. Sent messages cannot be recalled: after a timeout ' +
|
|
20
|
+
'or a dropped connection, send again with the same --idempotency-key, which answers the first records instead ' +
|
|
21
|
+
'of sending twice. --yes sends.',
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
name: '--type',
|
|
25
|
+
type: 'string',
|
|
26
|
+
choices: ['wxwork', 'ding_talk', 'webhook', 'email', 'sms'],
|
|
27
|
+
placeholder: '<type>',
|
|
28
|
+
description: 'wxwork, ding_talk, webhook, email or sms'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: '--channel',
|
|
32
|
+
type: 'string',
|
|
33
|
+
placeholder: '<id>',
|
|
34
|
+
description: 'Channel id, from `message channel list`. Required for a group robot, a webhook and SMS (an SMS channel sends ' +
|
|
35
|
+
"one template, once approved). Email may leave it out: it then goes from Jinshuju's address and uses the " +
|
|
36
|
+
"email quota; with one it goes through that channel's SMTP account"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: '--to',
|
|
40
|
+
type: 'string',
|
|
41
|
+
repeatable: true,
|
|
42
|
+
placeholder: '<recipient>',
|
|
43
|
+
description: 'Email address or mobile number for email and SMS, repeatable, at most 50'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: '--title',
|
|
47
|
+
type: 'string',
|
|
48
|
+
placeholder: '<text>',
|
|
49
|
+
description: 'Heading above the content, or the subject of an email'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: '--content',
|
|
53
|
+
type: 'string',
|
|
54
|
+
placeholder: '<text>',
|
|
55
|
+
description: "The message, in Markdown unless it mentions anyone on WeCom; an email's becomes HTML and takes up to " +
|
|
56
|
+
'20,000 characters'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: '--variable',
|
|
60
|
+
type: 'string',
|
|
61
|
+
repeatable: true,
|
|
62
|
+
placeholder: '<name>=<value>',
|
|
63
|
+
description: "Every variable the SMS channel's template declares, as it is named there (var_1...), each 1 to 100 " +
|
|
64
|
+
'characters; repeatable'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: '--mention',
|
|
68
|
+
type: 'string',
|
|
69
|
+
repeatable: true,
|
|
70
|
+
placeholder: '<mobile|@all>',
|
|
71
|
+
description: 'Group member to @ by mobile number, or @all for everyone; repeatable'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: '--idempotency-key',
|
|
75
|
+
type: 'string',
|
|
76
|
+
placeholder: '<key>',
|
|
77
|
+
description: 'Sends once for the same key within 24 hours; retry with the same key'
|
|
78
|
+
},
|
|
79
|
+
SEND_OPTION
|
|
80
|
+
],
|
|
81
|
+
request: (input) => {
|
|
82
|
+
const type = requiredOption(input, 'type');
|
|
83
|
+
if (!input.options.yes)
|
|
84
|
+
throw new UsageError('A sent message cannot be recalled; pass --yes to send');
|
|
85
|
+
const variables = input.options.variable;
|
|
86
|
+
return call('sendMessage', {
|
|
87
|
+
body: given({
|
|
88
|
+
type,
|
|
89
|
+
channel_id: input.options.channel,
|
|
90
|
+
to: input.options.to,
|
|
91
|
+
title: input.options.title,
|
|
92
|
+
content: input.options.content,
|
|
93
|
+
variables: variables && Object.fromEntries(variables.map(parseVariable)),
|
|
94
|
+
mentioned_mobile_list: input.options.mention,
|
|
95
|
+
idempotency_key: input.options.idempotency_key
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
examples: [
|
|
100
|
+
"jinshuju message send --type wxwork --channel 6729f1c2a1b2c3d4e5f60718 --content '今天是星期三,该吃午饭啦!' " +
|
|
101
|
+
'--mention 13800000000 --yes',
|
|
102
|
+
"jinshuju message send --type email --to someone@example.com --title 上课提醒 --content '明天上午 9 点开课' --yes",
|
|
103
|
+
'jinshuju message send --type sms --channel 6729f1c2a1b2c3d4e5f60719 --to 13800000000 --variable var_1=张三 ' +
|
|
104
|
+
'--variable var_2=9:00 --yes'
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
path: ['message', 'channel', 'list'],
|
|
109
|
+
summary: 'List the channels `message send` can send through, newest first',
|
|
110
|
+
description: 'The channels you registered, or every channel of the account for an account access token. The id goes to ' +
|
|
111
|
+
'`message send --channel`. address is the robot or webhook address with its key hidden, empty for email and ' +
|
|
112
|
+
'SMS; an email channel carries its smtp_account_id and an SMS one its sms_template_id.',
|
|
113
|
+
options: [
|
|
114
|
+
{
|
|
115
|
+
name: '--type',
|
|
116
|
+
type: 'string',
|
|
117
|
+
choices: choices('listMessageChannels', 'type'),
|
|
118
|
+
placeholder: '<type>',
|
|
119
|
+
description: 'Only the channels of this type: wxwork, ding_talk, webhook, email or sms'
|
|
120
|
+
},
|
|
121
|
+
...PAGINATION_OPTIONS
|
|
122
|
+
],
|
|
123
|
+
request: (input) => call('listMessageChannels', { query: { type: input.options.type, ...paging(input) } }),
|
|
124
|
+
paginate: LISTING,
|
|
125
|
+
examples: ['jinshuju message channel list', 'jinshuju message channel list --type sms']
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
path: ['message', 'channel', 'get'],
|
|
129
|
+
summary: 'Show a channel `message send` can send through',
|
|
130
|
+
args: [{ name: 'id', required: true, description: 'Channel id, from `message channel list`' }],
|
|
131
|
+
request: (input) => call('getMessageChannel', { path: { id: input.args.id } }),
|
|
132
|
+
examples: ['jinshuju message channel get 6729f1c2a1b2c3d4e5f60718']
|
|
133
|
+
}
|
|
134
|
+
];
|