After being admitted to Yale, I created a sophisticated bot called Yalebot to help out fellow 2023 students by answering FAQs and helping choose classes. I initially expected it to be a minor project.
Five months, 1486 commits, and 35,000 lines later, the bot is one of my most intricate creations. It can make memes, draw on photos using face recognition, host entire online games of Cards Against Humanity with a corresponding web interface, list available laundry machines on campus, give information about menus and capacity of Yale's dining halls, and literally hundreds of other features.
While building such a sophisticated piece of software, which is now one of the most complex GroupMe bots ever created, I began to bump up against some limits of the platform. Though GroupMe's bots API is powerful, it is best suited for simplistic bots that operate in only one chat group. As Yalebot grew in popularity and its featureset expanded, I had to build out an entire web-based control panel for allowing other users to add the bot to their own groups, and I had to architect a database system for persisting user data and keeping track of which bot instance corresponded to which group so that the bot could operate in parallel across multiple groups. Simply put, the multi-module program I was writing far outgrew the platform it was designed for.
At one point, I decided to extract one module of the bot, its Cards Against Humanity online game, into a separate bot. While doing so, I was bothered by the quantity of boilerplate code I had to bring over from the previous bot. It struck me that there should be some extensible platform upon which bots could be built that could create a common baseline for these sorts of chatbots.
What it does
MeBots, accessible at mebots.co, lowers the barrier of entry for creating large-scale GroupMe bots! It handles a lot of the database management and logic that you need to scale GroupMe bots up and make them flexible and usable by other people.
The platform, which has an associated Python package (Ruby, Go, and others coming soon) hosted on PyPI, allows any GroupMe user to log in and create their own bots, which can easily be added by anyone else to a group of which any user is a member. The application also eliminates much of the headache of managing a database of user and group data to keep track of which bot instance is which, and obscures some data that GroupMe typically reveals which may be dangerous for security.
With only two or three lines of Python code (similar in other languages), chatbot developers can streamline their bot code and focus on what matters most: functionality.
How I built it
I built MeBots by creating a Flask-based webserver program combined with a PostgreSQL database instance for storing all the data pertinent to the application. For ease of use by users, all authentication and user data is handled through GroupMe's API itself—users log in with GroupMe and their bots are associated to that actual GroupMe account.
I built a very convenient associated Python library which can be quite easily used to replace thousands of lines of management console and database wrangling code with only one or two lines of abstract API calls.
Challenges I ran into
I've never worked with GroupMe's Apps API in this much depth before, and figuring out how to automate queries to that platform was a big challenge. Additionally, ensuring that authentication state with GroupMe was maintained was tough because it needed to be consistently held throughout a user's session.
Accomplishments that I'm proud of
The connection state maintenance issue was very tough, but I ended up figuring it out through a prerequest hook that verifies connection with the GroupMe API and periodically pulls updates to user data. I am very happy that I was able to construct a very clean database schema for managing only the data I needed to manage while maintaining a minimalistic data suite.
What I learned
Since running queries to the GroupMe API on behalf of other users is a necessarily quite private endeavor, I learned a lot about how to balance use of user data with respect for their data ownership. I came up with several great compromises for allowing bot developers flexibility while not violating user privacy.
I also learned a lot about using SQL servers and clients on my local machine and creating local testing environments.
What's next for MeBots
The first large project I will need to undertake is migrating Yalebot, my inspiration for the project, to use the MeBots platform. The issue with this is not the complexity of the code—as mentioned before, migrating code to use the platform is extremely easy. The issue here is migration of data. While building MeBots I made many improvements to the means of data storage used in the database architecture, so the schema has changed a great deal. In the interest of making migration easy both for myself and future users, my #1 priority is to create a CSV import system which will allow coercion of data automatically into desired formats.
I also will restructure the user interface to suit wider screens better. From the screenshots of the website you might notice that the various forms elements especially are placed mostly in one line down the left side of the screen. I would really like to use cleaner alignment and use more grid-like positioning.
In a more major move for the platform, I plan to abstract away more laborious tasks that bots have to undertake, and generally wrap the GroupMe bots API more completely. For example, rather than making users request a bot ID from the MeBots API and then POSTing message data to the GroupMe API, it would be much cleaner if MeBots simply did the POST request itself. Furthermore, there should be more thorough management of callback URLs by MeBots; this way if a bot designer wants to restructure their endpoints and accept input differently, they can do so. Then, they can simply change the callback URL in the bot settings, and because each individual bot instance will actually be routing to a static endpoint of MeBots, it can automatically update rather than binding users to maintaining backward-compatibility forever.
After I make these software improvements, I want to promote the platform beyond my own social circles and work on spurring more traffic and use to the platform. Ultimately, I would absolutely love to get involved with GroupMe itself as an intern or similar, so as to have a chance to implement my work into GroupMe's own website. I think this could help their bot platform measure up to competitors such as Discord, which have similar systems in place already.