UNPKG

@anjir/app-novinhub

Version:

نوین هاب - پلتفرم کامل مدیریت شبکه‌های اجتماعی، دایرکت هوشمند، و خودکارسازی پیام‌رسانی

173 lines 7.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.novinhubUpdateAutomationMessageAction = 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.novinhubUpdateAutomationMessageAction = (0, apps_framework_1.createAction)({ auth: index_1.novinhubAuth, name: 'update_automation_message', displayName: 'ویرایش پیام خودکار', description: 'ویرایش پیام موجود در دایرکت هوشمند', props: { accountId: apps_framework_1.Property.Number({ displayName: 'شناسه اکانت', description: 'شناسه اکانت مربوط به پیام', required: true, }), messageId: apps_framework_1.Property.Number({ displayName: 'شناسه پیام', description: 'شناسه پیامی که می‌خواهید ویرایش کنید', required: true, }), title: apps_framework_1.Property.ShortText({ displayName: 'عنوان پیام', description: 'عنوان جدید پیام', required: true, }), type: apps_framework_1.Property.StaticDropdown({ displayName: 'نوع پیام', description: 'نوع محتوای پیام', required: true, options: { disabled: false, options: [ { label: 'متن', value: common_1.AUTOMATION_MESSAGE_TYPES.TEXT }, { label: 'دکمه', value: common_1.AUTOMATION_MESSAGE_TYPES.BUTTON }, { label: 'رسانه', value: common_1.AUTOMATION_MESSAGE_TYPES.MEDIA }, { label: 'محصولات', value: common_1.AUTOMATION_MESSAGE_TYPES.PRODUCTS }, ], }, }), text: apps_framework_1.Property.LongText({ displayName: 'متن پیام', description: 'محتوای متنی جدید پیام', required: true, }), // Quick Replies quick_replies: apps_framework_1.Property.Array({ displayName: 'پاسخ‌های سریع', description: 'لیست پاسخ‌های سریع برای کاربران', required: false, properties: { title: apps_framework_1.Property.ShortText({ displayName: 'عنوان پاسخ', description: 'متن روی دکمه پاسخ سریع', required: true, }), payload: apps_framework_1.Property.ShortText({ displayName: 'محتوای پاسخ', description: 'داده‌ای که هنگام کلیک ارسال می‌شود', required: true, }), }, }), // Buttons buttons: apps_framework_1.Property.Array({ displayName: 'دکمه‌ها', description: 'لیست دکمه‌های پیام', required: false, properties: { type: apps_framework_1.Property.StaticDropdown({ displayName: 'نوع دکمه', description: 'نوع دکمه', required: true, options: { disabled: false, options: [ { label: 'لینک', value: 'web_url' }, { label: 'عملیات', value: 'postback' }, ], }, }), title: apps_framework_1.Property.ShortText({ displayName: 'عنوان دکمه', description: 'متن روی دکمه', required: true, }), url: apps_framework_1.Property.ShortText({ displayName: 'آدرس لینک', description: 'آدرس URL برای دکمه‌های لینک', required: false, }), payload: apps_framework_1.Property.ShortText({ displayName: 'محتوای عملیات', description: 'داده‌ای که هنگام کلیک ارسال می‌شود', required: false, }), }, }), // File for media type file_id: apps_framework_1.Property.Number({ displayName: 'شناسه فایل', description: 'شناسه فایل برای پیام‌های رسانه‌ای', required: false, }), // Products for products type product_ids: apps_framework_1.Property.Array({ displayName: 'شناسه محصولات', description: 'لیست شناسه محصولات برای پیام‌های محصول', required: false, properties: { product_id: apps_framework_1.Property.Number({ displayName: 'شناسه محصول', description: 'شناسه محصول', required: true, }), }, }), }, async run(ctx) { const { accountId, messageId, title, type, text, quick_replies, buttons, file_id, product_ids } = ctx.propsValue; const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${ctx.auth.access_token}`, }; const body = { title, type, text, }; // Add optional fields based on type if (quick_replies && quick_replies.length > 0) { body.quick_replies = quick_replies; } if (buttons && buttons.length > 0) { body.buttons = buttons; } if (type === common_1.AUTOMATION_MESSAGE_TYPES.MEDIA && file_id) { body.file_id = file_id; } if (type === common_1.AUTOMATION_MESSAGE_TYPES.PRODUCTS && product_ids && product_ids.length > 0) { body.product_ids = product_ids.map((item) => item.product_id); } const url = (0, common_1.buildApiUrl)(`/automation/${accountId}/message/${messageId}`); try { const response = await apps_common_1.httpClient.sendRequest({ method: apps_common_1.HttpMethod.PUT, url: url, headers: headers, body: body, }); if (response.status === 200) { return { success: true, automation_message: 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=update-automation-message.js.map