Smart Media is represented in the eliza server as an object stored in redis & mongo, and is linked to a published Lens post. It essentially extends a regular post - like a post that is text only or post with an image - but with dynamic logic and functionality.
export type SmartMediaBase = {
agentId: UUID; // uuid
creator: `0x${string}`; // lens account
template: TemplateName;
category: TemplateCategory;
createdAt: number; // unix ts
updatedAt: number; // unix ts
templateData?: unknown; // specific data needed per template
}
export type LaunchpadToken = {
chain: LaunchpadChain; // base | lens
address: `0x${string}`;
}
export type SmartMedia = SmartMediaBase & {
postId: string; // lens post id
maxStaleTime: number; // seconds before the post should update
uri: URI; // lens storage node uri
token: LaunchpadToken; // associated token
versions?: [string]; // versions of uri; only present in the db
};
Each smart media is created from a Template, which defines how it should update, evolve, and potentially respond to changes in its social graph. The Template handler function is in charge or generating new metadata for the post.
Templates are defined in src/templates/ and adhere to this interface:
/**
* Represents a Smart Media template
*/
export interface Template {
/** Action name */
name: TemplateName;
/** Detailed description */
description: string;
/** Handler function */
handler: TemplateHandler;
}
/**
* Handler function for generating new metadata for a Smart Media post
*/
export type TemplateHandler = (
runtime: IAgentRuntime,
media?: SmartMedia,
templateData?: unknown,
) => Promise<TemplateHandlerResponse | null>;
/**
* Handler response where one of preview or metadata must be present
*/
export interface TemplateHandlerResponse {
preview?: { // not necessary for all templates
text: string;
image?: string; // base64
video?: string,
};
metadata?: TextOnlyMetadata | ImageMetadata | VideoMetadata; // only undefined on failure or generating preview
updatedUri?: string, // in case the handler wants versioning on the media
updatedTemplateData?: unknown, // updated payload for the next generation
}
Template Examples
We've built two examples of smart media templates that showcase how a post can evolve based on social graph interactions and onchain data.
Adventure Time
Choose your own adventure. Creator sets the context and inits the post with the first page. Weighted comments / upvotes decide the direction of the story.
Artist is Present
The artist is present in the evolving art. Creator sets the original image and style. The comment with the most votes dictates how the image evolves.