@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
62 lines • 2.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubFetchSocialPostsAction = void 0;
const apps_framework_1 = require("@anjir/apps-framework");
const apps_common_1 = require("@anjir/apps-common");
const index_1 = require("../../index");
exports.novinhubFetchSocialPostsAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'fetch_social_posts',
displayName: 'دریافت پستهای شبکه اجتماعی',
description: 'دریافت لیست آنلاین پستهای شبکه اجتماعی (در حال حاضر فقط اینستاگرام)',
props: {
accountId: apps_framework_1.Property.ShortText({
displayName: 'Account ID',
description: 'شناسه اکانت شبکه اجتماعی',
required: true,
}),
after: apps_framework_1.Property.ShortText({
displayName: 'After Cursor',
description: 'مقدار after برای دریافت صفحه بعدی (اختیاری)',
required: false,
}),
},
async run(ctx) {
const { accountId, after } = ctx.propsValue;
const headers = {
'Content-Type': 'application/json',
};
// ساخت query parameters
const queryParams = new URLSearchParams();
queryParams.append('access_token', ctx.auth.access_token);
if (after)
queryParams.append('after', after);
const url = `https://api.novinhub.com/v2/account/${accountId}/fetch-posts?${queryParams.toString()}`;
try {
const response = await apps_common_1.httpClient.sendRequest({
method: apps_common_1.HttpMethod.GET,
url: url,
headers: headers,
});
if (response.status === 200) {
return {
success: true,
posts: response.body.data || response.body,
pagination: response.body.paging || null,
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=fetch-social-posts.js.map