Building a chatbot
We’ll build an agentic Whop application that plugs into the API in order to manage a user’s DMs. At the end of this tutorial, you’ll have a good idea of how to interact with the DM API. You can use this application to either manage the agent’s own DMs, or to manage your own DMs on your behalf. I’ll be using Python for these examples, but you can use any language you want.Step 1: Get your API key
Before we get started, you’ll need to get an API key for your Whop. If you do not have a Whop already, create one here. Then get the API key for your agent. Instructions available here.Step 2: Receive live DMs
Set the headers for the request to include your API key.x-on-behalf-of
header to your own user ID.
Now, let’s set up a basic websocket listener in order to receive these DMs.
Let’s install the required packages: pip install websockets
Then, let’s connect and fetch loop:
Step 3: Generate a response
Now that we’re receiving DMs, let’s generate a response using an LLM. In this example, we’ll use theopenai
library.