spectrum-ts

repository·main·Indexed 22 days ago

https://github.com/photon-hq/spectrum-ts

A multi-channel agent framework by Photon that enables AI agents to communicate over real-world interfaces such as iMessage, Slack, Telegram, and the terminal. It includes a core runtime and a variety of platform providers and webhook adapters for ElysiaJS, Express, Fastify, and Hono.

Tokens
47.1K
Snippets
169
Records
209
Agent score
77%

What's inside spectrum-ts

  1. Quickstart: Create a Spectrum app with iMessage

    main

    To get started quickly with Spectrum Cloud, sign up at app.photon.codes to obtain a projectId and projectSecret.

    Use the Spectrum function to initialize your application with your credentials and desired providers. You can then iterate over app.messages using an for await...of loop to handle incoming messages. To respond to a message, use space.responding() to ensure safe concurrency/state management, and call message.reply() to send a response.

    import { Spectrum } from "spectrum-ts";
    import { imessage } from "spectrum-ts/providers/imessage";
    
    const app = await Spectrum({
      projectId: process.env.PROJECT_ID,
      projectSecret: process.env.PROJECT_SECRET,
      providers: [imessage.config()],
    });
    
    for await (const [space, message] of app.messages) {
      await space.responding(async () => {
        await message.reply("Hello from Spectrum.");
      });
    }
  2. Configure the iMessage provider in Spectrum

    main

    To initialize Spectrum with iMessage support, import the Spectrum factory and the imessage provider, then pass imessage.config() into the providers array.

    import { Spectrum } from "spectrum-ts";
    import { imessage } from "@spectrum-ts/imessage";
    
    const spectrum = Spectrum({
      providers: [imessage.config()],
    });
  3. Install Spectrum via bun

    main

    To install the batteries-included version of Spectrum (which includes the runtime and the standard provider set), use the following command:

    bun add spectrum-ts

    For a smaller installation, you can install only the core runtime and the specific providers you need (e.g., bun add @spectrum-ts/core @spectrum-ts/telegram). If you use the spectrum-ts/providers/<platform> import path, ensure the corresponding provider package is installed, otherwise the import will fail at build/startup with a message indicating which package to add.

  4. Install @spectrum-ts/imessage-local

    main

    To use the local macOS iMessage provider, you must install both the core spectrum-ts package and the @spectrum-ts/imessage-local provider.

    Note: This package is not included in the main spectrum-ts package by default. You should only install it on the macOS host that has direct access to the local Messages database.

    bun add spectrum-ts @spectrum-ts/imessage-local