🌳
Bonsai Docs
  • Introduction
    • Bonsai
    • What is Smart Media?
  • Platform
    • No-code creator studio
    • Guide: Create a post
  • Smart Media
    • Framework for builders
  • Building Smart Media
    • ElizaOS server setup
    • Bonsai Client
    • Templates
  • Guide: Create a Template
  • Client Integrations
    • Showing whether a post is Smart Media
    • Linking to Bonsai for remixes
  • Actions
    • Reward Swap
  • Launchpad
    • Overview
    • Getting Started
    • Launchpad Contract
    • Vesting ERC20 Contract
    • Hooks
    • API
      • Tokens
      • Token Balances
      • Buy / Sell Quotes
      • Link your token to a Lens Post & Account
  • ElizaOS
    • plugin-bonsai-launchpad
    • client-lens
Powered by GitBook
On this page
  • Checking metadata attributes
  • Resolving the full Smart Media object
  1. Client Integrations

Showing whether a post is Smart Media

PreviousClient IntegrationsNextLinking to Bonsai for remixes

Last updated 16 hours ago

When rendering Lens posts on a social feed, we can show the user whether or not it's a Smart Media post. For now, all posts made on Bonsai are Smart Media posts. This can change in the future, as we support regular posts, or other Lens apps support the creation of Smart Media.

Checking metadata attributes

If you only want to show whether a post is Smart Media with the category or template name, you can do so by inspecting the post metadata attributes.

import { Post } from "@lens-protocol/client";

type SmartMediaLight = {
  template?: { id: string, formatted: string },
  category?: { id: string, formatted: string },
  mediaUrl?: string,
  isCanvas?: boolean;
}

export const fetchSmartMedia = async (post: Post): Promise<SmartMediaLight | null> => {
  const LENS_BONSAI_APP = "0x640c9184b31467C84096EB2829309756DDbB3f44";
  // handle root post
  const attributes = !post.root ? post.metadata.attributes : post.root.metadata.attributes;

  const isSmartMedia = post.app?.address === LENS_BONSAI_APP && attributes?.some(attr => attr.key === 'template');
  if (!isSmartMedia) return null;
  const template = post.metadata.attributes?.find(({ key }) => key === "template");
  const category = post.metadata.attributes?.find(({ key }) => key === "templateCategory");
  const mediaUrl = post.metadata.attributes?.find(({ key }) => key === "apiUrl");
  const isCanvas = post.metadata.attributes?.find(({ key }) => key === "isCanvas");

  return {
    ...(template && {
      template: {
        id: template.value,
        formatted: template.value.toLowerCase().replace(/_/g, ' ').replace(/\b\w/g, char => char.toUpperCase())
      }
    }),
    ...(category && {
      category: {
        id: category.value,
        formatted: category.value.toLowerCase().replace(/_/g, ' ').replace(/\b\w/g, char => char.toUpperCase())
      }
    }),
    mediaUrl: mediaUrl?.value,
    isCanvas: !!isCanvas?.value
  }
}
{
  template: { id: 'adventure_time', formatted: 'Adventure Time' },
  category: { id: 'evolving_post', formatted: 'Evolving Post' },
  mediaUrl: 'https://eliza.onbons.ai',
  isCanvas: false
}

The above information is enough to render the screenshot shown in the beginning of this doc.

Resolving the full Smart Media object

If you want to render more information, like shown in the GIF above, you can easily get the full Smart Media object using our API. This would provide information such as

  • the description of the smart media template (its behavior as defined by the developer)

  • the last time the smart media object was updated / generated

  • whether the smart media object is currently updating

  • the full configuration of the smart media object (useful for more bespoke integrations)

API ENDPOINT: https://app.onbons.ai/api/media/{postSlug}

METHOD: GET

{
    "category": "evolving_post",
    "template": "adventure_time",
    "agentId": "11dec834-6fb0-0e6c-a702-2da0fb4df111",
    "creator": "0x94734e11b78680a35b0a86ba3ce634d334d6d2a7",
    "templateData": {
        "context": "Snowboard trip to the Mountains of Japan. Filled with snowboard action and tricks. and beautiful views. Take the challenge",
        "writingStyle": "Motivationa, Casual tone",
        "modelId": "flux-dev",
        "stylePreset": "Long Exposure",
        "decisions": [
            "Head back to the lodge for some well-deserved rest and hot chocolate.",
            "Continue exploring the mountain for more thrills."
        ],
        "chapterName": "Frozen Sanctuary",
        "aspectRatio": "1:1",
        "previousPages": [
            "First Descent; Take the safe route, a well-groomed path with gentle slopes ideal for warming up.",
            "The Backcountry Call; Strike out into the backcountry for a more challenging and exhilarating run.",
            "Untouched Powder; Conquer the steep incline, pushing your skills to the limit for an unforgettable ride.",
            "The Hidden Cave; Explore the cave further, unravelling its mysteries and potential hidden treasures."
        ]
    },
    "postId": "3bkqx29zpdv30r8b7ms",
    "uri": "lens://4abbe5d2e326dba189de39e7ab53fb609b2fbd9b8b75e50bdbd10b04376c4d8e",
    "maxStaleTime": 1800,
    "createdAt": 1746660711,
    "updatedAt": 1746727482,
    "versionCount": 4,
    "isProcessing": false,
    "versions": [
        "https://link.storjshare.io/raw/jw3iog3dy7frukpkum5xo6tklyxq/publication-history-metadata/f0781eae-4884-4cc8-93c9-8363ac71d3ff-version-0.json",
        "https://link.storjshare.io/raw/jw3iog3dy7frukpkum5xo6tklyxq/publication-history-metadata/aad4c3d8-cbfb-42ea-ad68-79a8712c5be5-version-1.json",
        "https://link.storjshare.io/raw/jw3iog3dy7frukpkum5xo6tklyxq/publication-history-metadata/d2fee46b-6ee3-42a0-b283-213eb031e812-version-2.json",
        "https://link.storjshare.io/raw/jw3iog3dy7frukpkum5xo6tklyxq/publication-history-metadata/eef4f170-b569-48f9-be17-b82754549f49-version-3.json"
    ],
    "protocolFeeRecipient": "0x21aF1185734D213D45C6236146fb81E2b0E8b821",
    "description": "The creator sets the stage for an evolving choose-your-own-adventure. Collectors & token holders decide the direction of the story.",
    "estimatedCost": 1.082,
    "status": "active",
    "featured": true
}
Property
Description

category

the top-level smart media category

template

the template name, as defined by the template developer

description

the template description, as defined by the template developer. describes the behavior of this smart media object

agentId

unique UUID on the ElizaOS server

templateData

custom config data necessary to continue generations for this smart media object

postId

associated Lens post slug

uri

associated Lens post uri

isProcessing

whether the smart media object is currently updating / re-generating

versions

array of URLs that resolve to Post metadata of past versions of this post

protocolFeeRecipient

developer defined recipient of any protocol fee splits

estimatedCost

the estimated cost (in credits) to re-generate this post

status

the latest generation status

featured

whether the post is featured on Bonsai

For example, would return the following:

For example, would return the following:

this post
this post
Each post (when hovered) on the Bonsai Feed shows the category of Smart Media
When viewing a full post, we show more details about eh Smart Media