@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
216 lines • 9.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubCreatePostAction = void 0;
const apps_framework_1 = require("@anjir/apps-framework");
const apps_common_1 = require("@anjir/apps-common");
const index_1 = require("../../index");
exports.novinhubCreatePostAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'create_post',
displayName: 'ایجاد پست',
description: 'ایجاد پست جدید در شبکههای اجتماعی از طریق نوین هاب',
props: {
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' },
{ label: 'استوری', value: 'story' },
{ label: 'نظرسنجی', value: 'poll' },
],
},
}),
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": "کپشن مخصوص تلگرام"
}
}),
poll: apps_framework_1.Property.Json({
displayName: 'Poll',
description: 'تنظیمات نظرسنجی (فقط برای type=poll)',
required: false,
defaultValue: {
"question": "سوال نظرسنجی",
"answers": ["گزینه ۱", "گزینه ۲"]
}
}),
// Instagram specific
reels: apps_framework_1.Property.Checkbox({
displayName: 'Instagram Reels',
description: 'پست به شکل ریلز ارسال شود (اینستاگرام)',
required: false,
}),
first_comment: apps_framework_1.Property.ShortText({
displayName: 'First Comment',
description: 'نظر اول (اینستاگرام)',
required: false,
}),
// Telegram specific
telegram_pin_message: apps_framework_1.Property.Checkbox({
displayName: 'Telegram Pin Message',
description: 'پست در بالای کانال پین شود (تلگرام)',
required: false,
}),
telegram_has_signature: apps_framework_1.Property.Checkbox({
displayName: 'Telegram Signature',
description: 'یوزرنیم کانال به انتهای متن اضافه شود (تلگرام)',
required: false,
}),
telegram_buttons: apps_framework_1.Property.Array({
displayName: 'Telegram Buttons',
description: 'دکمههای شیشهای تلگرام (فرمت: ["عنوان:لینک"])',
required: false,
}),
// YouTube specific
youtube_title: apps_framework_1.Property.ShortText({
displayName: 'YouTube Title',
description: 'عنوان ویدیو یوتیوب',
required: false,
}),
youtube_privacy: apps_framework_1.Property.StaticDropdown({
displayName: 'YouTube Privacy',
description: 'حریم خصوصی یوتیوب',
required: false,
options: {
disabled: false,
options: [
{ label: 'عمومی', value: 'public' },
{ label: 'خصوصی', value: 'private' },
{ label: 'غیرفهرست', value: 'unlisted' },
],
},
}),
// LinkedIn specific
linkedin_title: apps_framework_1.Property.ShortText({
displayName: 'LinkedIn Title',
description: 'عنوان ویدیو لینکدین',
required: false,
}),
},
async run(ctx) {
const { caption, type, account_ids, media_ids, is_scheduled, schedule_date, is_draft, location, hashtag, custom_captions, poll, reels, first_comment, telegram_pin_message, telegram_has_signature, telegram_buttons, youtube_title, youtube_privacy, linkedin_title, } = ctx.propsValue;
const headers = {
'Content-Type': 'application/json',
};
const url = `https://api.novinhub.com/v2/post?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 (poll && type === 'poll')
body.poll = poll;
// فیلدهای مخصوص اینستاگرام
if (reels)
body.reels = 1;
if (first_comment)
body.first_comment = first_comment;
// فیلدهای مخصوص تلگرام
if (telegram_pin_message)
body.telegram_pin_message = 1;
if (telegram_has_signature)
body.telegram_has_signature = 1;
if (telegram_buttons && telegram_buttons.length > 0)
body.telegram_buttons = telegram_buttons;
// فیلدهای مخصوص یوتیوب
if (youtube_title)
body.youtube_title = youtube_title;
if (youtube_privacy)
body.youtube_privacy = youtube_privacy;
// فیلدهای مخصوص لینکدین
if (linkedin_title)
body.linkedin_title = linkedin_title;
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=create-post.js.map