Skip to content

TypeScript social media agent (Mastra)

An AI agent for social media research, built on a TypeScript-native framework.

Create it locally

$scrapely create my-actor --template ts-mastraai

Main file

.TS
src/main.ts
import { Actor, log } from 'scrapely';

import { createWebResearchAgent } from './agents.js';

// this is ESM project, and as such, it requires you to specify extensions in your relative imports
// read more about this here: https://nodejs.org/docs/latest-v18.x/api/esm.html#mandatory-file-extensions
// note that we need to use `.js` even when inside TS files
// import { router } from './routes.js';

// Actor input schema
interface Input {
    query: string;
    modelName: string;
}

// The init() call configures the Actor to correctly work with the platform-provided environment - mainly the storage infrastructure. It is necessary that every Actor performs an init() call.
await Actor.init();

/**
 * Actor code
 */

// Handle input
const {
    // The query default value is provided only for template testing purposes.
    // You can remove it.
    query,
    modelName,
} = (await Actor.getInput()) as Input;
if (!query) {
    throw new Error('An agent query is required.');
}

// Create the web research agent with tools
const agent = createWebResearchAgent(modelName);

log.info(`Querying the agent with the following query: ${query}`);

// Query the agent and get the response
const response = await agent.generate([{ role: 'user', content: query }]);

log.info(`Agent response: ${response.text}`);

// Charge for the task completion
await Actor.charge({ eventName: 'task-completed' });

// Push results into the dataset
await Actor.pushData({
    query,
    response: response.text,
});

// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit()
await Actor.exit();

TypeScript web research agent (Mastra)

A Mastra agent that researches websites with a page-scraping tool, built on a TypeScript-native framework.

Included features

  • Scrapely SDK — Actor lifecycle, input, storage and proxies
  • Mastra — TypeScript agent framework
  • Scrapely LLM gateway — call OpenRouter models with the run token; usage is billed to your Scrapely account, no provider API key needed
  • Input schema — define and validate the Actor's input (.actor/input_schema.json)
  • Dataset schema — structured results with a preview view (.actor/dataset_schema.json)

Getting started locally

npm install
npm run start      # run the Actor
npm run build      # compile to dist/

LLM calls go to SCRAPELY_LLM_BASE_URL (set automatically on the platform) with the run's SCRAPELY_TOKEN, so the agent works inside a Scrapely run without any provider API key.

Deploying to Scrapely

Create an Actor from this template in the Scrapely Console (Develop new → template → Git). Scrapely creates a repository in your account, pushes this code, and builds the Actor. Every push to your repository triggers a new build.

G2
4.7/5
Excellent
Trustpilot

The internet is full of data.
Start owning yours.

Scrape.ly gives you the infrastructure, the tooling, and the team to extract, process, and operationalize web data at any scale. Setup takes minutes. The advantage lasts forever.

No credit card. No setup calls.