@yaoyuanchao/dingtalk 1.4.13 → 1.4.14
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/package.json +1 -1
- package/src/api.ts +12 -4
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -167,18 +167,26 @@ export async function sendDingTalkRestMessage(params: {
|
|
|
167
167
|
userId?: string;
|
|
168
168
|
conversationId?: string;
|
|
169
169
|
text: string;
|
|
170
|
+
format?: 'text' | 'markdown';
|
|
170
171
|
}): Promise<{ ok: boolean }> {
|
|
171
172
|
const token = await getDingTalkAccessToken(params.clientId, params.clientSecret);
|
|
172
173
|
const headers = { "x-acs-dingtalk-access-token": token };
|
|
173
174
|
|
|
175
|
+
// Use markdown format by default for better rendering
|
|
176
|
+
const useMarkdown = params.format !== 'text';
|
|
177
|
+
const msgKey = useMarkdown ? 'sampleMarkdown' : 'sampleText';
|
|
178
|
+
const msgParam = useMarkdown
|
|
179
|
+
? JSON.stringify({ title: 'AI', text: params.text })
|
|
180
|
+
: JSON.stringify({ content: params.text });
|
|
181
|
+
|
|
174
182
|
if (params.userId) {
|
|
175
183
|
const res = await jsonPost(
|
|
176
184
|
`${DINGTALK_API_BASE}/robot/oToMessages/batchSend`,
|
|
177
185
|
{
|
|
178
186
|
robotCode: params.robotCode,
|
|
179
187
|
userIds: [params.userId],
|
|
180
|
-
msgKey
|
|
181
|
-
msgParam
|
|
188
|
+
msgKey,
|
|
189
|
+
msgParam,
|
|
182
190
|
},
|
|
183
191
|
headers,
|
|
184
192
|
);
|
|
@@ -194,8 +202,8 @@ export async function sendDingTalkRestMessage(params: {
|
|
|
194
202
|
{
|
|
195
203
|
robotCode: params.robotCode,
|
|
196
204
|
openConversationId: params.conversationId,
|
|
197
|
-
msgKey
|
|
198
|
-
msgParam
|
|
205
|
+
msgKey,
|
|
206
|
+
msgParam,
|
|
199
207
|
},
|
|
200
208
|
headers,
|
|
201
209
|
);
|