Introducing API and AI plugins

Level Up Your Robo.js Game

We've got something special for you today! Say hello to two new plugins that are sure to elevate your Robo.js experience, and guess what? They come with zero dependencies.

API Plugin 🛠️

Simple, Yet Powerful APIs

If you've admired how Next.js simplifies API route handling, you're in for a treat.

How to Use It

Creating an API is straightforward. Drop a JavaScript file under /src/api, and you've defined an API route. For instance, creating a test.js file in /src/api gives you a /api/test route.

export default (request, reply) => {
  console.log(`API Request body:`, request.body);

  return {
    message: 'Congrats on making an API call!',
    success: true
  };
};

After this, just fire up your Robo project and navigate to http://localhost:3000/api/test to see it in action.

Note: If you prefer, you can always fall back on the Node req and res objects via request.req and reply.res.

Customization

By default, the server listens on port 3000. Need to switch things up? No worries. Here's how to adjust the port and enable CORS:

// File: /config/plugins/roboplay/api.mjs
export default {
  cors: true,
  port: 4000
};

Remember, other plugins can also add their own API routes, so the sky's the limit.

Setup

Installation is as easy as:

npm install @roboplay/plugin-api

And that's it!

AI Plugin 🧠

It's Alive! (Sort of)

Add some AI to your Discord Robo and make it a lot more interactive and responsive.

Usage Basics

It's super simple. Just @-mention your AI-enabled Robo or reply to its messages, and you're chatting!

Tailoring the Experience

If you'd like to customize your AI Robo's behavior, all you need to do is add a system message in your config:

// File: /config/plugins/roboplay/ai.mjs
export default {
  openaiKey: process.env.OPENAI_KEY,
  systemMessage: 'You should behave like a caring and empathetic individual in a playful mood'
};

Commanding Attention

Your Robo can also handle its own Discord slash commands!

Enable it in your config like this:

// File: /config/plugins/roboplay/ai.mjs
export default {
  // ... your other configs
  commands: true
};
Warning: Be mindful of GPT token usage. You can limit the commands by specifying an array like commands: ['joinvc', 'ban', 'kick'].

API Interactions

With the API plugin installed, you can even converse with your AI Robo outside Discord. Make a POST request to /api/ai/chat:

{
  "messages": [
    {
      "content": "Reply in a very kawaii tone",
      "role": "system"
    },
    {
      "content": "Hai Robo, talk to me!",
      "role": "user"
    }
  ]
}

Getting Started

First, make sure you have an OpenAI account and then run:

npm install @roboplay/plugin-ai

And that's it! You're all set to make your Robo.js projects more dynamic and engaging. Let us know how you're using these new tools; we can't wait to see what you'll create next.

New Robo? 🚀

Starting fresh? Let's get you set up!

For a brand new Robo, run this in your terminal:

npx create-robo <your-robo-name>

You'll see an option to include our new API and AI plugins during the setup. Pick 'em and you're good to go.

📝 Note: Node.js 18+ is needed. Make sure you're up-to-date.

Already have a Robo? Just install the plugins via npm and add them to your config.

Easy peasy. Now go make some Robo magic! 🎉