|
1 |
| -from tools.helper import tool_registry, ACCESS_TOKEN, load_from_gptscript_workspace |
| 1 | +from tools.helper import ACCESS_TOKEN, load_from_gptscript_workspace |
2 | 2 | from linkedin_api.clients.restli.client import RestliClient
|
3 | 3 | from tools.users import get_user
|
4 | 4 | import os
|
5 | 5 | import requests
|
6 | 6 |
|
7 | 7 |
|
8 |
| -@tool_registry.register_tool("CreatePost") |
9 |
| -async def create_post(client: RestliClient): |
| 8 | +async def create_post(client: RestliClient) -> dict: |
10 | 9 | r = get_user(client)
|
11 | 10 | user_id = r["sub"]
|
12 | 11 | content = os.getenv("CONTENT")
|
@@ -97,10 +96,14 @@ async def create_post(client: RestliClient):
|
97 | 96 | raise ValueError(
|
98 | 97 | f"Error: failed to create post. Status code: {response.status_code}. Response: {response.entity}"
|
99 | 98 | )
|
| 99 | + |
| 100 | + response.entity["link"] = ( |
| 101 | + f"https://www.linkedin.com/feed/update/{response.entity['id']}" # craft the link manually |
| 102 | + ) |
100 | 103 | return response.entity
|
101 | 104 |
|
102 | 105 |
|
103 |
| -def _register_upload(client: RestliClient, category: str): |
| 106 | +def _register_upload(client: RestliClient, category: str) -> tuple[str, dict]: |
104 | 107 | url = "https://api.linkedin.com/v2/assets?action=registerUpload"
|
105 | 108 |
|
106 | 109 | headers = {
|
@@ -145,7 +148,7 @@ def _register_upload(client: RestliClient, category: str):
|
145 | 148 | )
|
146 | 149 |
|
147 | 150 |
|
148 |
| -async def _upload_registered_file(file_path, upload_url): |
| 151 | +async def _upload_registered_file(file_path, upload_url) -> int: |
149 | 152 | headers = {
|
150 | 153 | "Authorization": f"Bearer {ACCESS_TOKEN}",
|
151 | 154 | "Content-Type": "application/octet-stream",
|
|
0 commit comments