Skip to content

Commit

Permalink
fix: handle special characters in post content
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperKoza343 committed Jan 21, 2025
1 parent b59503e commit 5f1bf38
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
29 changes: 19 additions & 10 deletions packages/client-linkedin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { validateConfig } from "./helpers/validate-config";
import axios from "axios";
import { LinkedInUserInfoFetcher } from "./repositories/LinkedinUserInfoFetcher";
import { LinkedInPostScheduler } from "./services/LinkedInPostScheduler";
import { LinkedInPostPublisher } from "./repositories/LinkedinPostPublisher";
import { PostContentCreator } from "./services/PostContentCreator";

export const LinkedInClient: Client = {
async start(runtime: IAgentRuntime) {
Expand All @@ -14,18 +16,25 @@ export const LinkedInClient: Client = {
"Authorization": `Bearer ${envs.LINKEDIN_ACCESS_TOKEN}`,
},
});
const { sub } = await new LinkedInUserInfoFetcher(axiosInstance).getUserInfo();
const newPostContentCreator = new PostContentCreator(runtime);
const postContentPublisher = new LinkedInPostPublisher(axiosInstance, sub);

const linkedInPostScheduler = await LinkedInPostScheduler.createPostScheduler({
axiosInstance,
userInfoFetcher: new LinkedInUserInfoFetcher(axiosInstance),
runtime,
config: {
LINKEDIN_DRY_RUN: envs.LINKEDIN_DRY_RUN,
LINKEDIN_POST_INTERVAL_MIN: envs.LINKEDIN_POST_INTERVAL_MIN,
LINKEDIN_POST_INTERVAL_MAX: envs.LINKEDIN_POST_INTERVAL_MAX,
}
await postContentPublisher.publishPost({
postText: newPostContentCreator.encodePostContent(newPostContentCreator.removeMd("Rola pamięć mięsniowej w treningu (Role of Motor Memory in Training)\n\nDid you know that motor memory can be trained independently of conscious memory? Research suggests that repeated practice of a motor task can establish a stable, long-term memory representation that can be recalled even in the absence of conscious awareness. \n\nThis concept is crucial for professionals in fields such as sports, physical rehabilitation, and education, as it highlights the importance of implicit learning and motor skill acquisition. By understanding the role of motor memory in training, you can optimize your instruction methods and improve learning outcomes.\n\nFor example, consider the task of learning a new golf swing. Conscious practice focuses on correcting technique and form, whereas implicit practice (e.g., repetition of movement without attention to detail) relies on motor memory to establish a consistent swing pattern.\n\nImplementation detail: In a study on golf swing training, researchers found that participants who received implicit practice (unconscious repetition) showed significant improvement in swing accuracy compared to those who received conscious practice (focused on technique).\n\nTechnical discussion question: How can you integrate implicit practice into your training programs to leverage the power of motor memory?\n\n#MotorLearning #NeuralPlasticity #SkillAcquisition")),
});
linkedInPostScheduler.createPostPublicationLoop();
console.log("Published post");
// const linkedInPostScheduler = await LinkedInPostScheduler.createPostScheduler({
// axiosInstance,
// userInfoFetcher: new LinkedInUserInfoFetcher(axiosInstance),
// runtime,
// config: {
// LINKEDIN_DRY_RUN: envs.LINKEDIN_DRY_RUN,
// LINKEDIN_POST_INTERVAL_MIN: envs.LINKEDIN_POST_INTERVAL_MIN,
// LINKEDIN_POST_INTERVAL_MAX: envs.LINKEDIN_POST_INTERVAL_MAX,
// }
// });
// linkedInPostScheduler.createPostPublicationLoop();


return this;
Expand Down
18 changes: 17 additions & 1 deletion packages/client-linkedin/src/services/PostContentCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ export class PostContentCreator {
modelClass: ModelClass.SMALL,
});

return removeMd(text);
return this.removeMd(this.escapeSpecialCharacters(text));
}

removeMd(content: string) {
return removeMd(content);
}

escapeSpecialCharacters(content: string): string {
const escapedCharacters = content
.replace(/\(/g, "\\(")
.replace(/\)/g, "\\)")
.replace(/\[/g, "\\[")
.replace(/\]/g, "\\]")
.replace(/\{/g, "\\{")
.replace(/\}/g, "\\}");

return escapedCharacters;
}
}

0 comments on commit 5f1bf38

Please sign in to comment.