@anjir/app-novinhub
Version:
نوین هاب - پلتفرم کامل مدیریت شبکههای اجتماعی، دایرکت هوشمند، و خودکارسازی پیامرسانی
72 lines • 2.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.novinhubCreateAccountGroupAction = 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.novinhubCreateAccountGroupAction = (0, apps_framework_1.createAction)({
auth: index_1.novinhubAuth,
name: 'create_account_group',
displayName: 'ایجاد گروه اکانت',
description: 'ایجاد گروه جدید برای مجموعهای از اکانتها',
props: {
name: apps_framework_1.Property.ShortText({
displayName: 'نام گروه',
description: 'نام گروه اکانت',
required: true,
}),
account_ids: apps_framework_1.Property.Array({
displayName: 'شناسههای اکانت',
description: 'لیست شناسه اکانتهایی که در این گروه قرار میگیرند',
required: true,
properties: {
account_id: apps_framework_1.Property.Number({
displayName: 'شناسه اکانت',
description: 'شناسه اکانت',
required: true,
}),
},
}),
},
async run(ctx) {
const { name, account_ids } = ctx.propsValue;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${ctx.auth.access_token}`,
};
// Extract account IDs from the array format
const accountIdList = account_ids.map((item) => item.account_id);
const body = {
name,
account_ids: accountIdList,
};
const url = (0, common_1.buildApiUrl)('/account-group');
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,
account_group: 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-account-group.js.map