@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
64 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubCreateCaptionAction = 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.novinhubCreateCaptionAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'create_caption',
displayName: 'ایجاد کپشن',
description: 'ایجاد کپشن جدید در نوین هاب',
props: {
title: apps_framework_1.Property.ShortText({
displayName: 'عنوان کپشن',
description: 'عنوان کپشن برای شناسایی آسان',
required: true,
}),
caption: apps_framework_1.Property.LongText({
displayName: 'متن کپشن',
description: 'متن کامل کپشن',
required: true,
}),
},
async run(ctx) {
const { title, caption } = ctx.propsValue;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${ctx.auth.access_token}`,
};
const body = {
title,
caption,
type: 'direct',
};
const url = (0, common_1.buildApiUrl)('/caption');
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,
caption: 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-caption.js.map