The Bitte AI Chat component is a React component that enables AI-powered chat interactions in your application. It supports both NEAR Protocol and EVM blockchain interactions through wallet integrations, allowing users to interact with smart contracts and perform transactions directly through the chat interface.
Import and use BitteAiChat in your react app and select the agent that you would like to use, browse the available agents and their respective ids on the registry
The apiUrl corresponds to a proxy to not expose your api key on the client
import {BitteAiChat} from "@bitte-ai/chat";
<BitteAiChat
agentId="your-agent-id"
apiUrl="/api/chat"
/>
3. Setup API Route
Create an API route in your Next.js application to proxy requests to the Bitte API to not expose your key
At this point the chat should already work but to be able to send transactions you will need to add a wallet connection
4. Add wallet connection
NEAR Integration
You can integrate with NEAR using either the NEAR Wallet Selector or a direct account connection. If you want to be able to send near transacitons through the chat you will need to define at least one of these
import { Account } from "near-api-js";
// get near account instance from near-api-js by instantiating a keypair
<BitteAiChat
agentId="your-agent-id"
apiUrl="/api/chat"
wallet={{ near: { account: nearAccount } }}
/>
EVM Integration
EVM integration uses WalletConnect with wagmi hooks:
The component can be customized using the colors prop:
type ChatComponentColors = {
generalBackground?: string; // Chat container background
messageBackground?: string; // Message bubble background
textColor?: string; // Text color
buttonColor?: string; // Button color
borderColor?: string; // Border color
};
Browser Redirects (Optional)
if you're having issues with your app or wallet containing redirects you can optionally use a history api to maintain context
Create an API route in your Next.js application that will allow your app if you want to save chat context when signing a transaction after getting redirected to the wallet.