Skip to content

upstash/hacker-news-x-agent

Repository files navigation

Hacker News X Agent with Workflow

This is a simple agent that fetches the top stories from Hacker News and tweets a summary. Agent orchestration is done using @upstash/workflow agents.

To see the agent in action, follow @hackernewsagent on X.

To learn more about how the agent works, check out our blog post.

Setup Instructions

Using the Vercel Deploy Button

You can deploy this agent to Vercel with a single click using the Vercel Deploy Button found found at the top of this file. Fill the environment variables as described in the next steps.

Fill Environment Variables

  1. Clone this repository.
git clone https://github.com/upstash/hacker-news-x-agent.git
  1. Install dependencies.
npm install
  1. Create a .env.local file in the root directory and copy the contents from .env.local.example. Fill these environment variables following the instructions in the next steps.

  2. Go to QStash tab on Upstash Console. Fill the following environment variables in .env.local with the values found in the Environment Keys section:

# To power the workflow
QSTASH_TOKEN=

# To make sure requests are coming from the right source
QSTASH_CURRENT_SIGNING_KEY=
QSTASH_NEXT_SIGNING_KEY=
  1. Go to Redis tab on Upstash Console. Create a new Redis database and fill the following environment variables in .env.local with the values found in the REST API section .env tab:
# To keep track of the news articles visited
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
  1. Go to OpenAI Platform -> API Keys and create a new API key. Fill the following environment variables in .env.local:
# To power the agent
OPENAI_API_KEY=
  1. Go to ideogram and create a new API key. Fill the following environment variables in .env.local:
# To generate images
IDEOGRAM_API_KEY=
8. Set up X API
  1. Go to X Website and create an account.

1-create-x-account

  1. Go to X Developer Portal and sign up for a a free developer account.

2-create-x-developer-account

  1. Fill the developer agreement & policy according to your needs.

3-fill-developer-policy

  1. Go to project settings.

4-go-project-settings

  1. Set up User authentication settings.

5-set-up-user-auth-settings

  1. Fill the form and save.

6-user-auth-settings-form-part-1

7-user-auth-settings-form-part-2

  1. Make sure User authentication is set up.

8-check-user-auth-settings-set-up

  1. Fill the following environment variables in .env.local with the values found under the Keys and tokens tab:
# To be able to tweet
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=

9-keys-and-tokens

Deploy the Agent

  1. Deploy the agent to Vercel.
vercel
  1. Go to the Vercel Dashboard -> Your Project -> Environment Variables and paste the contents of .env.local there, you don't need to set them one by one.

  2. Deploy the agent to production.

vercel --prod

Calling the Agent

  1. To secure the calls to the agent, only requests signed by QStash are allowed. If you don't want this security layer, you can just leave the following environment variables empty. You can learn more about how to Secure an endpoint with our guide.
# To make sure requests are coming from the right source
QSTASH_CURRENT_SIGNING_KEY=
QSTASH_NEXT_SIGNING_KEY=
  1. Go to QStash tab on Upstash Console and publish a message.

11-qstash-publish

Schedule the Agent

  1. Go to QStash tab on Upstash Console and create a new schedule with Request Builder. Keep the limits of X API and QStash in mind while setting the schedule frequency. Cron expression 0 */2 * * * will run the agent every 2 hours.

10-qstash-schedule

Local Development

  1. Check out our Local Development Guide to learn how to work with @upstash/workflow agents locally.

  2. You can run the agent locally with the following command:

npm run dev

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published