@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
120 lines • 4.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubReplyToConversationAction = void 0;
const apps_framework_1 = require("@anjir/apps-framework");
const apps_common_1 = require("@anjir/apps-common");
const index_1 = require("../../index");
const common_1 = require("../common");
exports.novinhubReplyToConversationAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'reply_to_conversation',
displayName: 'پاسخ به مکالمه',
description: 'ارسال پاسخ جدید در یک مکالمه',
props: {
conversationId: apps_framework_1.Property.Number({
displayName: 'شناسه مکالمه',
description: 'شناسه مکالمهای که میخواهید در آن پاسخ دهید',
required: true,
}),
content: apps_framework_1.Property.LongText({
displayName: 'متن پیام',
description: 'محتوای متنی پیام',
required: true,
}),
attachment: apps_framework_1.Property.File({
displayName: 'فایل پیوست',
description: 'فایل ارسالی در پیام (اختیاری)',
required: false,
}),
// Generics (Sliders)
generics: apps_framework_1.Property.Json({
displayName: 'اسلایدرها (Generics)',
description: 'لیست اسلایدرهای پیام',
required: false,
defaultValue: [
{
"title": "عنوان اسلایدر",
"subtitle": "متن توضیحی",
"image_url": "https://example.com/image.jpg",
"defaultActionUrl": "https://example.com",
"buttons": [
{
"type": "web_url",
"title": "مشاهده",
"url": "https://example.com"
}
]
}
],
}),
// Buttons
buttons: apps_framework_1.Property.Json({
displayName: 'دکمهها',
description: 'لیست دکمههای پیام',
required: false,
defaultValue: [
{
"type": "url",
"title": "عنوان دکمه",
"url": "https://example.com"
},
{
"type": "postback",
"title": "انتخاب",
"payload": "action_data"
}
],
}),
},
async run(ctx) {
const { conversationId, content, attachment, generics, buttons } = ctx.propsValue;
const headers = {
'Authorization': `Bearer ${ctx.auth.access_token}`,
};
const formData = new FormData();
formData.append('content', content);
// Add attachment if provided
if (attachment) {
formData.append('attachment', new Blob([attachment.data]), attachment.filename);
}
// Add generics if provided
if (generics && Array.isArray(generics) && generics.length > 0) {
formData.append('generics', JSON.stringify(generics));
}
// Add buttons if provided
if (buttons && Array.isArray(buttons) && buttons.length > 0) {
const buttonData = {
content: content,
buttons: buttons,
};
formData.append('buttons', JSON.stringify(buttonData));
}
const url = (0, common_1.buildApiUrl)(`/conversation/${conversationId}/reply`);
try {
const response = await apps_common_1.httpClient.sendRequest({
method: apps_common_1.HttpMethod.POST,
url: url,
headers: headers,
body: formData,
});
if (response.status === 200 || response.status === 201) {
return {
success: true,
data: response.body,
message: 'پاسخ با موفقیت ارسال شد',
};
}
else {
throw new Error(`خطا در ارسال پاسخ: ${response.body?.message || `HTTP ${response.status}`}`);
}
}
catch (error) {
const errorMessage = error.message || error.toString() || 'خطا در ارسال پاسخ';
return {
success: false,
error: errorMessage,
};
}
},
});
//# sourceMappingURL=reply-to-conversation.js.map