UNPKG

@anjir/app-novinhub

Version:

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

98 lines 4.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.novinhubCreateAutomationQuestionsAction = 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.novinhubCreateAutomationQuestionsAction = (0, apps_framework_1.createAction)({ auth: index_1.novinhubAuth, name: 'create_automation_questions', displayName: 'ایجاد سوالات متداول', description: 'ایجاد سوالات متداول جدید برای دایرکت (حداکثر 4 سوال)', props: { accountId: apps_framework_1.Property.Number({ displayName: 'شناسه اکانت', description: 'شناسه اکانتی که سوالات برای آن ایجاد می‌شود', required: true, }), questions: apps_framework_1.Property.Array({ displayName: 'سوالات متداول', description: 'لیست سوالات متداول (حداکثر 4 سوال)', required: true, properties: { title: apps_framework_1.Property.ShortText({ displayName: 'عنوان سوال', description: 'متن سوال متداول', required: true, }), message_ids: apps_framework_1.Property.ShortText({ displayName: 'شناسه پیام‌ها', description: 'لیست شناسه پیام‌هایی که به این سوال مرتبط هستند (جدا شده با کاما)', required: true, }), type: apps_framework_1.Property.StaticDropdown({ displayName: 'نوع', description: 'نوع سوال (مقدار ثابت message)', required: true, options: { disabled: false, options: [ { label: 'پیام', value: 'message' }, ], }, }), }, }), }, async run(ctx) { const { accountId, questions } = ctx.propsValue; const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${ctx.auth.access_token}`, }; // Validate maximum 4 questions if (questions.length > 4) { return { success: false, error: 'حداکثر 4 سوال متداول می‌توانید ایجاد کنید', }; } // Process questions const processedQuestions = questions.map((question) => ({ title: question.title, message_ids: question.message_ids.split(',').map((id) => parseInt(id.trim())), type: question.type, })); const body = { menu: processedQuestions, }; const url = (0, common_1.buildApiUrl)(`/automation/${accountId}/question`); try { const response = await apps_common_1.httpClient.sendRequest({ method: apps_common_1.HttpMethod.POST, url: url, headers: headers, body: body, }); if (response.status === 200 || response.status === 201) { return { success: true, automation_questions: 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=create-automation-questions.js.map