UNPKG

@anjir/app-novinhub

Version:

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

153 lines 6.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.novinhubEditPostAction = void 0; const apps_framework_1 = require("@anjir/apps-framework"); const apps_common_1 = require("@anjir/apps-common"); const index_1 = require("../../index"); exports.novinhubEditPostAction = (0, apps_framework_1.createAction)({ auth: index_1.novinhubAuth, name: 'edit_post', displayName: 'ویرایش پست', description: 'ویرایش پست موجود در نوین هاب', props: { postGroupId: apps_framework_1.Property.ShortText({ displayName: 'Post Group ID', description: 'شناسه گروه پست برای ویرایش', required: true, }), caption: apps_framework_1.Property.LongText({ displayName: 'Caption', description: 'متن کپشن جدید پست', required: true, }), type: apps_framework_1.Property.StaticDropdown({ displayName: 'Post Type', description: 'نوع پست', required: true, options: { disabled: false, options: [ { label: 'متن', value: 'text' }, { label: 'تصویر', value: 'image' }, { label: 'آلبوم', value: 'album' }, { label: 'ویدیو', value: 'video' }, { label: 'سند', value: 'document' }, ], }, }), account_ids: apps_framework_1.Property.Array({ displayName: 'Account IDs', description: 'آرایه‌ای از شناسه‌های اکانت‌های مقصد', required: true, }), media_ids: apps_framework_1.Property.Array({ displayName: 'Media IDs', description: 'آرایه‌ای از شناسه‌های فایل‌های رسانه (اختیاری)', required: false, }), is_scheduled: apps_framework_1.Property.Checkbox({ displayName: 'Is Scheduled', description: 'آیا پست زمان‌بندی شده است؟', required: false, }), schedule_date: apps_framework_1.Property.DateTime({ displayName: 'Schedule Date', description: 'تاریخ زمان‌بندی پست (در صورت زمان‌بندی)', required: false, }), is_draft: apps_framework_1.Property.Checkbox({ displayName: 'Is Draft', description: 'آیا پست پیش‌نویس است؟', required: false, }), location: apps_framework_1.Property.ShortText({ displayName: 'Location', description: 'موقعیت مکانی (اختیاری)', required: false, }), hashtag: apps_framework_1.Property.Array({ displayName: 'Hashtags', description: 'آرایه‌ای از هشتگ‌ها (اختیاری)', required: false, }), custom_captions: apps_framework_1.Property.Json({ displayName: 'Custom Captions', description: 'کپشن‌های سفارشی بر اساس شبکه اجتماعی (اختیاری)', required: false, defaultValue: { "instagram": "کپشن مخصوص اینستاگرام", "telegram": "کپشن مخصوص تلگرام" } }), photo_tags: apps_framework_1.Property.Json({ displayName: 'Photo Tags', description: 'تگ‌های تصویر (اختیاری)', required: false, defaultValue: { "media_id_1": [ { "locationX": 0.5, "locationY": 0.3, "text": "نام کاربر", "id": "user_pk_id" } ] } }), }, async run(ctx) { const { postGroupId, caption, type, account_ids, media_ids, is_scheduled, schedule_date, is_draft, location, hashtag, custom_captions, photo_tags, } = ctx.propsValue; const headers = { 'Content-Type': 'application/json', }; const url = `https://api.novinhub.com/v2/post/${postGroupId}?access_token=${ctx.auth.access_token}`; const body = { caption, type, account_ids, }; // اضافه کردن فیلدهای اختیاری if (media_ids && media_ids.length > 0) body.media_ids = media_ids; if (is_scheduled) body.is_scheduled = 1; if (schedule_date) body.schedule_date = Math.floor(new Date(schedule_date).getTime() / 1000); if (is_draft) body.is_draft = 1; if (location) body.location = location; if (hashtag && hashtag.length > 0) body.hashtag = hashtag; if (custom_captions) body.custom_captions = custom_captions; if (photo_tags) body.photo_tags = photo_tags; 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, post: 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=edit-post.js.map