This repository contains the code for a Slack bot application that uses MongoDB App Services serverless functions and OpenAI's API to generate funny responses to user queries based on news data.
The application is powered by several JavaScript functions that interact with MongoDB, Slack, and OpenAI's API. It also uses MongoDB App Services triggers to automate certain tasks, such as fetching news stories and responding to user queries. The application runs on an hourly schedule, fetching the latest news stories and storing them in a MongoDB Atlas database.
Here is a brief overview of the key components:
-
realm_config.json
: The main configuration file for the MongoDB App Services application. -
functions/
: This directory contains the JavaScript functions that power the application. These functions handle tasks such as sending messages to Slack, generating responses using OpenAI's API, saving news articles to the database, and responding to incoming webhooks from Slack. -
triggers/
: This directory contains the configurations for MongoDB App Services triggers. These triggers automate tasks such as fetching news stories and responding to user queries. -
http_endpoints/
andgraphql/
: These directories contain configurations for the HTTP endpoints and GraphQL, respectively. -
data_sources/
: This directory contains the configuration for connecting to MongoDB Atlas. -
auth/
: This directory contains configurations related to authentication. -
environments/
: This directory contains environment-specific configurations. -
values/
: This directory contains various values used by the application, such as the OpenAI API key.
The application is triggered to run on an hourly basis. Here is how it works:
-
The
fetch_newsStories.json
trigger is activated, which runs thesave_newsArticles.js
function. This function fetches the latest news stories and saves them to the MongoDB Atlas database. -
When a user sends a query to the Slack bot, the
respond_to_question.json
trigger is activated. This trigger runs theask_question.js
function, which uses OpenAI's API to generate a funny response based on the user's query and the news data. -
The response from OpenAI's API is sent back to the user on Slack using the
slack_send.js
function.
I have added a file called mug_demo.news_stories.zip
at the root of the folder. This has all of the embeddings collected to date for you to play around with. You can load these into a collection.
Before running this application, you need to make sure that MongoDB App Services is properly set up and the required API keys for Slack and OpenAI are available. You will also need access to a MongoDB Atlas database where the application will store the news data. You can do all of this on the free tier.
Here are the general steps to get the application up and running:
Configure your atlas search index after you have loaded the data.
A good guide is here MongoDB Vector Search Tutorial
- Clone this repository.
- Go to the MongoDB App Services dashboard and import the application configuration from the
realm_config.json
file. - Set up the MongoDB Atlas data source according to the configuration in
data_sources/mongodb-atlas/config.json
. - Set up the authentication providers according to the configuration in
auth/providers.json
. - Set up the OpenAI API key in
values/openai_api_key.json
. - Deploy the application in MongoDB App Services.
- Set up the Slack bot and configure it to use the webhook function for incoming messages.
Please note that these are general steps and might need to be adjusted based on your specific setup.
For detailed instructions on how to use MongoDB Realm, please refer to the official MongoDB Atlas App documentation. For instructions on how to set up a Slack bot, refer to the official Slack documentation.