embedchain/docs/examples/nextjs-assistant.mdx
Fork the Embedchain repo on Github to create your own NextJS discord and slack bot powered by Embedchain.
If you run into problems with forking, please refer to github docs for forking a repo.
We will work from the examples/nextjs folder so change your current working directory by running the command - cd <your_forked_repo>/examples/nextjs
First, lets start by install all the required packages and dependencies.
Install all the required python packages by running pip install -r requirements.txt
We will use Fly.io to deploy our embedchain app, discord and slack bot. Follow the step one to install Fly.io CLI
First, we need an Embedchain app powered with the knowledge of NextJS. We have already created an embedchain app using FastAPI in ec_app folder for you. Feel free to ingest data of your choice to power the App.
Before running the ec commands to develope the app, open fly.toml file and update the name variable to something unique. This is important as fly.io requires users to provide a globally unique deployment app names.
Now, we need to launch this application with fly.io. You can see your app on fly.io dashboard. Run the following command to launch your app on fly.io:
fly launch --no-deploy
To run the app in development, run the following command:
ec dev
Run ec deploy to deploy your app on Fly.io. Once you deploy your app, save the endpoint on which our discord and slack bot will send requests.
For discord bot, you will need to create the bot on discord developer portal and get the discord bot token and your discord bot name.
While keeping in mind the following note, create the discord bot by following the instructions from our discord bot docs and get discord bot token.
<Note> You do not need to set `OPENAI_API_KEY` to run this discord bot. Follow the remaining instructions to create a discord bot app. We recommend you to give the following sets of bot permissions to run the discord bot without errors:(General Permissions)
Read Message/View Channels
(Text Permissions)
Send Messages
Create Public Thread
Create Private Thread
Send Messages in Thread
Manage Threads
Embed Links
Read Message History
Once you have your discord bot token and discord app name. Navigate to nextjs_discord folder and create .env file and define your discord bot token, discord bot name and endpoint of your embedchain app as shown in .env.example file.
To run the app in development:
python app.py
Before deploying the app, open fly.toml file and update the name variable to something unique. This is important as fly.io requires users to provide a globally unique deployment app names.
Now, we need to launch this application with fly.io. You can see your app on fly.io dashboard. Run the following command to launch your app on fly.io:
fly launch --no-deploy
Run ec deploy to deploy your app on Fly.io. Once you deploy your app, your discord bot will be live!
For Slack bot, you will need to create the bot on slack developer portal and get the slack bot token and slack app token.
From Scratch, then enter the Bot Name and select your workspace.App Credentials section on the Basic Information tab from the left sidebar, create your app token and save it in your .env file as SLACK_APP_TOKEN.Socket Mode tab from the left sidebar and enable the socket mode to listen to slack message from your workspace.App Home tab you can change your App display name and default name.Event Subscription tab, and enable the event subscription so that we can listen to slack events.Add Bot User Event button and select app_mention.OAuth and Permissions and add the following scopes under Bot Token Scopes:app_mentions:read
channels:history
channels:read
chat:write
emoji:read
reactions:write
reactions:read
Install to Workspace and after it's done, copy the Bot User OAuth Token and set it in your .env file as SLACK_BOT_TOKEN.Once you have your slack bot token and slack app token. Navigate to nextjs_slack folder and create .env file and define your slack bot token, slack app token and endpoint of your embedchain app as shown in .env.example file.
To run the app in development:
python app.py
Before deploying the app, open fly.toml file and update the name variable to something unique. This is important as fly.io requires users to provide a globally unique deployment app names.
Now, we need to launch this application with fly.io. You can see your app on fly.io dashboard. Run the following command to launch your app on fly.io:
fly launch --no-deploy
Run ec deploy to deploy your app on Fly.io. Once you deploy your app, your slack bot will be live!