@memberjunction/actions-bizapps-social
Version:
Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer
157 lines • 6.84 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedInGetPersonalPostsAction = void 0;
const global_1 = require("@memberjunction/global");
const linkedin_base_action_1 = require("../linkedin-base.action");
const core_1 = require("@memberjunction/core");
const actions_1 = require("@memberjunction/actions");
/**
* Action to get posts from a LinkedIn personal profile
*/
let LinkedInGetPersonalPostsAction = class LinkedInGetPersonalPostsAction extends linkedin_base_action_1.LinkedInBaseAction {
/**
* Get posts from the authenticated user's LinkedIn profile
*/
async InternalRunAction(params) {
const { Params, ContextUser } = params;
try {
// Initialize OAuth
const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID');
if (!await this.initializeOAuth(companyIntegrationId)) {
throw new Error('Failed to initialize OAuth connection');
}
// Extract parameters
const count = this.getParamValue(Params, 'Count') || 50;
const startIndex = this.getParamValue(Params, 'StartIndex') || 0;
const includeAnalytics = this.getParamValue(Params, 'IncludeAnalytics') === true;
// Get current user URN
const userUrn = await this.getCurrentUserUrn();
(0, core_1.LogStatus)(`Fetching posts for user: ${userUrn}`);
// Get posts
const shares = await this.getShares(userUrn, count, startIndex);
// Convert to common format
const posts = [];
for (const share of shares) {
const post = this.normalizePost(share);
// Personal posts have limited analytics access
if (includeAnalytics) {
try {
// Note: Personal share analytics are limited compared to organization analytics
const analytics = await this.getPersonalPostAnalytics(share.id);
if (analytics) {
post.analytics = this.normalizeAnalytics(analytics);
}
}
catch (error) {
(0, core_1.LogError)(`Failed to get analytics for post ${share.id}: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
posts.push(post);
}
(0, core_1.LogStatus)(`Retrieved ${posts.length} personal posts`);
// Update output parameters
const outputParams = [...Params];
const postsParam = outputParams.find(p => p.Name === 'Posts');
if (postsParam)
postsParam.Value = posts;
const totalCountParam = outputParams.find(p => p.Name === 'TotalCount');
if (totalCountParam)
totalCountParam.Value = posts.length;
return {
Success: true,
ResultCode: 'SUCCESS',
Message: `Successfully retrieved ${posts.length} personal posts`,
Params: outputParams
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
return {
Success: false,
ResultCode: 'ERROR',
Message: `Failed to get personal posts: ${errorMessage}`,
Params
};
}
}
/**
* Get analytics for a personal post
* Note: LinkedIn provides limited analytics for personal posts
*/
async getPersonalPostAnalytics(shareId) {
try {
// LinkedIn v2 API has limited personal analytics
// We can get basic engagement data from the share itself
const response = await this.axiosInstance.get(`/ugcPosts/${shareId}`);
if (response.data) {
// Extract available metrics from the post data
return {
totalShareStatistics: {
impressionCount: 0, // Not available for personal posts
clickCount: 0, // Not available for personal posts
engagement: 0, // Not available for personal posts
likeCount: response.data.likesSummary?.totalLikes || 0,
commentCount: response.data.commentsSummary?.totalComments || 0,
shareCount: 0, // Not available in this endpoint
uniqueImpressionsCount: 0 // Not available for personal posts
}
};
}
return null;
}
catch (error) {
(0, core_1.LogError)(`Failed to get personal post analytics: ${error instanceof Error ? error.message : 'Unknown error'}`);
return null;
}
}
/**
* Define the parameters this action expects
*/
get Params() {
return [
...this.commonSocialParams,
{
Name: 'Count',
Type: 'Input',
Value: 50
},
{
Name: 'StartIndex',
Type: 'Input',
Value: 0
},
{
Name: 'IncludeAnalytics',
Type: 'Input',
Value: false
},
{
Name: 'Posts',
Type: 'Output',
Value: null
},
{
Name: 'TotalCount',
Type: 'Output',
Value: null
}
];
}
/**
* Get action description
*/
get Description() {
return 'Retrieves posts from the authenticated user\'s LinkedIn personal profile with limited analytics data';
}
};
exports.LinkedInGetPersonalPostsAction = LinkedInGetPersonalPostsAction;
exports.LinkedInGetPersonalPostsAction = LinkedInGetPersonalPostsAction = __decorate([
(0, global_1.RegisterClass)(actions_1.BaseAction, 'LinkedInGetPersonalPostsAction')
], LinkedInGetPersonalPostsAction);
//# sourceMappingURL=get-personal-posts.action.js.map