Quickstart: Create a Spectrum app with iMessage
mainTo 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.");
});
}