Skip to content

Commit 8c6fdae

Browse files
committed
fix: client integration, post generation
1 parent 2f8eb1c commit 8c6fdae

File tree

7 files changed

+71
-22
lines changed

7 files changed

+71
-22
lines changed

agent/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@elizaos/client-lens": "workspace:*",
3131
"@elizaos/client-telegram": "workspace:*",
3232
"@elizaos/client-twitter": "workspace:*",
33+
"@elizaos/client-instagram": "workspace:*",
3334
"@elizaos/client-slack": "workspace:*",
3435
"@elizaos/core": "workspace:*",
3536
"@elizaos/plugin-0g": "workspace:*",
@@ -103,4 +104,4 @@
103104
"ts-node": "10.9.2",
104105
"tsup": "8.3.5"
105106
}
106-
}
107+
}

agent/src/index.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase";
66
import { AutoClientInterface } from "@elizaos/client-auto";
77
import { DiscordClientInterface } from "@elizaos/client-discord";
88
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
9+
import { InstagramClientInterface } from "@elizaos/client-instagram";
910
import { LensAgentClient } from "@elizaos/client-lens";
1011
import { SlackClientInterface } from "@elizaos/client-slack";
1112
import { TelegramClientInterface } from "@elizaos/client-telegram";
@@ -39,12 +40,12 @@ import { zgPlugin } from "@elizaos/plugin-0g";
3940
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
4041
import createGoatPlugin from "@elizaos/plugin-goat";
4142
// import { intifacePlugin } from "@elizaos/plugin-intiface";
42-
import { DirectClient } from "@elizaos/client-direct";
4343
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
4444
import { abstractPlugin } from "@elizaos/plugin-abstract";
4545
import { alloraPlugin } from "@elizaos/plugin-allora";
4646
import { aptosPlugin } from "@elizaos/plugin-aptos";
4747
import { artheraPlugin } from "@elizaos/plugin-arthera";
48+
import { autonomePlugin } from "@elizaos/plugin-autonome";
4849
import { availPlugin } from "@elizaos/plugin-avail";
4950
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
5051
import { binancePlugin } from "@elizaos/plugin-binance";
@@ -56,8 +57,8 @@ import {
5657
tradePlugin,
5758
webhookPlugin,
5859
} from "@elizaos/plugin-coinbase";
59-
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
6060
import { coingeckoPlugin } from "@elizaos/plugin-coingecko";
61+
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
6162
import { confluxPlugin } from "@elizaos/plugin-conflux";
6263
import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
6364
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
@@ -76,7 +77,6 @@ import { obsidianPlugin } from "@elizaos/plugin-obsidian";
7677
import { sgxPlugin } from "@elizaos/plugin-sgx";
7778
import { solanaPlugin } from "@elizaos/plugin-solana";
7879
import { solanaAgentkitPlguin } from "@elizaos/plugin-solana-agentkit";
79-
import { autonomePlugin } from "@elizaos/plugin-autonome";
8080
import { storyPlugin } from "@elizaos/plugin-story";
8181
import { suiPlugin } from "@elizaos/plugin-sui";
8282
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
@@ -86,23 +86,22 @@ import { tonPlugin } from "@elizaos/plugin-ton";
8686
import { webSearchPlugin } from "@elizaos/plugin-web-search";
8787

8888
import { giphyPlugin } from "@elizaos/plugin-giphy";
89+
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
8990
import { letzAIPlugin } from "@elizaos/plugin-letzai";
9091
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
91-
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
9292
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
9393

94+
import { akashPlugin } from "@elizaos/plugin-akash";
9495
import { OpacityAdapter } from "@elizaos/plugin-opacity";
9596
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
96-
import { stargazePlugin } from "@elizaos/plugin-stargaze";
97-
import { akashPlugin } from "@elizaos/plugin-akash";
9897
import { quaiPlugin } from "@elizaos/plugin-quai";
98+
import { stargazePlugin } from "@elizaos/plugin-stargaze";
9999
import Database from "better-sqlite3";
100100
import fs from "fs";
101101
import net from "net";
102102
import path from "path";
103103
import { fileURLToPath } from "url";
104104
import yargs from "yargs";
105-
import {dominosPlugin} from "@elizaos/plugin-dominos";
106105

107106
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
108107
const __dirname = path.dirname(__filename); // get the name of the directory
@@ -556,6 +555,13 @@ export async function initializeClients(
556555
}
557556
}
558557

558+
if (clientTypes.includes(Clients.INSTAGRAM)) {
559+
const instagramClient = await InstagramClientInterface.start(runtime);
560+
if (instagramClient) {
561+
clients.instagram = instagramClient;
562+
}
563+
}
564+
559565
if (clientTypes.includes(Clients.FARCASTER)) {
560566
// why is this one different :(
561567
const farcasterClient = new FarcasterAgentClient(runtime);
13.2 MB
Loading

packages/client-instagram/src/environment.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
} from "@elizaos/core";
55
import { z } from "zod";
66

7-
export const DEFAULT_POST_INTERVAL_MIN = 90; // 1.5 hours
8-
export const DEFAULT_POST_INTERVAL_MAX = 180; // 3 hours
9-
export const DEFAULT_ACTION_INTERVAL = 5; // 5 minutes
7+
export const DEFAULT_POST_INTERVAL_MIN = 1;
8+
export const DEFAULT_POST_INTERVAL_MAX = 2;
9+
export const DEFAULT_ACTION_INTERVAL = 5;
1010
export const DEFAULT_MAX_ACTIONS = 1;
1111
export const DEFAULT_RETRY_LIMIT = 5;
1212

packages/client-instagram/src/services/post.ts

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// src/services/post.ts
22
import { IAgentRuntime, ModelClass, composeContext, elizaLogger, generateText, getEmbeddingZeroVector, stringToUuid } from "@elizaos/core";
3+
import { promises as fs } from 'fs';
4+
import path, { dirname } from "path";
35
import sharp from 'sharp';
6+
import { fileURLToPath } from 'url';
47
import { getIgClient } from "../lib/state";
58
import { InstagramState } from "../types";
69

@@ -155,7 +158,6 @@ export class InstagramPostService {
155158
}
156159

157160
// For Instagram, we need to generate or get an image
158-
// This is a placeholder - you'll need to implement image generation/selection
159161
const mediaUrl = await this.getOrGenerateImage(cleanedContent);
160162

161163
await this.createPost({
@@ -181,22 +183,31 @@ export class InstagramPostService {
181183
});
182184

183185
} catch (error) {
184-
elizaLogger.error("Error generating Instagram post:", error);
186+
elizaLogger.error("Error generating Instagram post:", {
187+
error: error instanceof Error ? error.message : String(error),
188+
stack: error instanceof Error ? error.stack : undefined,
189+
phase: 'generateNewPost'
190+
});
185191
}
186192
}
187193

188194
// Placeholder - implement actual image generation/selection
189195
private async getOrGenerateImage(content: string): Promise<string> {
190196
// This should be implemented based on your image generation strategy
191197
// Could use DALL-E, Stable Diffusion, or select from a preset collection
192-
return "path/to/default/image.jpg";
198+
const __filename = fileURLToPath(import.meta.url);
199+
const __dirname = dirname(__filename);
200+
return path.resolve(__dirname, '../assets/goku.png');
193201
}
194202

195203
async createPost(options: PostOptions) {
196204
const ig = getIgClient();
197205

198206
try {
199-
elizaLogger.log("Creating Instagram post");
207+
elizaLogger.log("Creating Instagram post", {
208+
mediaCount: options.media.length,
209+
hasCaption: !!options.caption
210+
});
200211

201212
// Process media
202213
const processedMedia = await Promise.all(
@@ -224,7 +235,8 @@ export class InstagramPostService {
224235
if (media.type === 'VIDEO') {
225236
await ig.publish.video({
226237
video: media.buffer,
227-
caption: options.caption
238+
caption: options.caption,
239+
coverImage: media.buffer
228240
});
229241
} else {
230242
await ig.publish.photo({
@@ -242,16 +254,23 @@ export class InstagramPostService {
242254

243255
elizaLogger.log("Instagram post created successfully");
244256
} catch (error) {
245-
elizaLogger.error("Error creating Instagram post:", error);
257+
elizaLogger.error("Error creating Instagram post:", {
258+
error: error instanceof Error ? error.message : String(error),
259+
stack: error instanceof Error ? error.stack : undefined,
260+
phase: 'createPost',
261+
mediaCount: options.media.length,
262+
hasCaption: !!options.caption
263+
});
246264
throw error;
247265
}
248266
}
249267

250268
private async processMedia(media: { type: string; url: string }): Promise<Buffer> {
251269
try {
252-
const response = await fetch(media.url);
253-
const arrayBuffer = await response.arrayBuffer();
254-
const buffer = Buffer.from(arrayBuffer);
270+
elizaLogger.log("Processing media", { type: media.type, url: media.url });
271+
272+
// Read file directly from filesystem instead of using fetch
273+
const buffer = await fs.readFile(media.url);
255274

256275
if (media.type === 'IMAGE') {
257276
// Process image with sharp
@@ -270,7 +289,13 @@ export class InstagramPostService {
270289
// For other types, return original buffer
271290
return buffer;
272291
} catch (error) {
273-
elizaLogger.error("Error processing media:", error);
292+
elizaLogger.error("Error processing media:", {
293+
error: error instanceof Error ? error.message : String(error),
294+
stack: error instanceof Error ? error.stack : undefined,
295+
phase: 'processMedia',
296+
mediaType: media.type,
297+
url: media.url
298+
});
274299
throw error;
275300
}
276301
}

packages/core/src/types.ts

+14
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ export enum Clients {
649649
AUTO = "auto",
650650
SLACK = "slack",
651651
GITHUB = "github",
652+
INSTAGRAM = "instagram",
652653
}
653654

654655
export interface IAgentConfig {
@@ -732,6 +733,9 @@ export type Character = {
732733
twitterPostTemplate?: TemplateType;
733734
twitterMessageHandlerTemplate?: TemplateType;
734735
twitterShouldRespondTemplate?: TemplateType;
736+
instagramPostTemplate?: TemplateType;
737+
instagramMessageHandlerTemplate?: TemplateType;
738+
instagramShouldRespondTemplate?: TemplateType;
735739
farcasterPostTemplate?: TemplateType;
736740
lensPostTemplate?: TemplateType;
737741
farcasterMessageHandlerTemplate?: TemplateType;
@@ -869,10 +873,20 @@ export type Character = {
869873
bio: string;
870874
nicknames?: string[];
871875
};
876+
877+
/** Optional Instagram profile */
878+
instagramProfile?: {
879+
id: string;
880+
username: string;
881+
bio: string;
882+
nicknames?: string[];
883+
};
884+
872885
/** Optional NFT prompt */
873886
nft?: {
874887
prompt: string;
875888
};
889+
876890
/**Optinal Parent characters to inherit information from */
877891
extends?: string[];
878892
};

pnpm-lock.yaml

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)