A basic web server
This tutorial shows you a minimal example of a web server that can use composio
Install dependencies
using bun
for this example, it is super convenient for rapid prototyping.
Please set the following environment variables:
The full source code is available here.
In this tutorial, we will create an auth config, initiate a connection, and send an email.
Setup
Basic scaffolding for the server.
Auth Configs
These are configurations for tools that control how they are authorized, the scopes and permissions they have. You can learn more about them here.
For this example, we will create a basic GMAIL auth config.
You are recommend to store these config ids, so that you can reuse them later.
Initiating a connection
Connections are your users authorizing your tools.
Here we start the connection process, once your user uses the redirectUrl
from the response,
they will be redirected to the auth flow.
Once they have authorized the connection, you can use the id
to get and execute the tools as the user.
You can test your server by running bun run index.ts
and then running the following command:
Sending an email
Now let’s send that email.
Using the id
from the connection, we can now send an email.
Full Code
You can see the full code here.
What just happened?
Well first - we created an instance of our gmail
tool with our default auth config, then our user authorized that tool with their account and some permissions.
Then we used that gmail
tool by giving it to OpenAI’s gpt-4o
. The model composed the email and sent it correctly formatted to the composio team.
What’s next?
This is a fairly basic example, but you can do a lot more with our sdk.
Recommended further reading:
- Authenticating tools - understand how to control tool authorization
- Executing Tools - understand how tool execution works
- Providers - want to use something other than OpenAI? we probably support it
- Tools - understand what tools we have