n8n-nodes-wechat-work
Version:
133 lines • 4.59 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const n8n_workflow_1 = require("n8n-workflow");
const WechatWorkRequestUtils_1 = __importDefault(require("../../../help/utils/WechatWorkRequestUtils"));
const GroupChatSendOperate = {
name: '发送群聊消息',
value: 'appGroupChat:send',
description: '发送消息到群聊',
options: [
{
displayName: '*群聊ID',
name: 'chatid',
default: '',
description: '群聊的唯一标志',
type: 'string',
required: true,
},
{
displayName: '*消息类型',
name: 'msgtype',
default: 'text',
type: 'options',
options: [
{ name: '文本消息', value: 'text' },
{ name: '图片消息', value: 'image' },
{ name: '语音消息', value: 'voice' },
{ name: '视频消息', value: 'video' },
{ name: '文件消息', value: 'file' },
{ name: '文本卡片消息', value: 'textcard' },
{ name: '图文消息', value: 'news' },
{ name: '图文消息(MPNEWS)', value: 'mpnews' },
{ name: 'MARKDOWN消息', value: 'markdown' },
],
required: true,
},
{
displayName: '*消息内容',
name: 'content',
default: '',
description: '消息内容,最长不超过2048个字节',
type: 'string',
displayOptions: {
show: {
msgtype: ['text', 'markdown'],
},
},
required: true,
},
{
displayName: '*媒体文件ID',
name: 'media_id',
default: '',
description: '媒体文件ID,可以调用上传临时素材接口获取',
type: 'string',
displayOptions: {
show: {
msgtype: ['image', 'voice', 'video', 'file'],
},
},
required: true,
},
{
displayName: '视频消息的标题',
name: 'title',
default: '',
description: '视频消息的标题,不超过128个字节',
type: 'string',
displayOptions: {
show: {
msgtype: ['video'],
},
},
},
{
displayName: '视频消息的描述',
name: 'description',
default: '',
description: '视频消息的描述,不超过512个字节',
type: 'string',
displayOptions: {
show: {
msgtype: ['video'],
},
},
},
{
displayName: '是否是保密消息',
name: 'safe',
default: false,
type: 'boolean',
},
],
async call(index) {
const chatid = this.getNodeParameter('chatid', index);
const msgtype = this.getNodeParameter('msgtype', index);
const safe = this.getNodeParameter('safe', index, false) ? 1 : 0;
let data = {
chatid,
msgtype,
safe,
};
if (msgtype === 'text' || msgtype === 'markdown') {
data[msgtype] = {
content: this.getNodeParameter('content', index),
};
}
else if (msgtype === 'image' || msgtype === 'voice' || msgtype === 'file') {
data[msgtype] = {
media_id: this.getNodeParameter('media_id', index),
};
}
else if (msgtype === 'video') {
data.video = {
media_id: this.getNodeParameter('media_id', index),
title: this.getNodeParameter('title', index, ''),
description: this.getNodeParameter('description', index, ''),
};
}
else {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), '暂不支持的消息类型');
}
return WechatWorkRequestUtils_1.default.request.call(this, {
method: 'POST',
url: `/cgi-bin/appchat/send`,
body: data,
});
},
};
exports.default = GroupChatSendOperate;
//# sourceMappingURL=GroupChatSendOperate.js.map