Building a ChatGPT Bot for iMessage Using BlueBubbles (2024)

A bot you can create for your iMessage chats

Building a ChatGPT Bot for iMessage Using BlueBubbles (1)

·

Follow

Published in

Better Programming

·

8 min read

·

Mar 17

--

Building a ChatGPT Bot for iMessage Using BlueBubbles (3)

A handful of years ago, I started an endeavor to create an open-source alternative to AirMessage, called BlueBubbles. If you aren’t familiar with the apps, they basically enable the use of iMessage on Android, Windows, or Linux, via a macOS proxy device. Now, I won’t go into all the details, but throughout the years, I’ve been adding features to BlueBubbles allowing users to build their own ecosystem of integrations.

The first step was creating a REST API to allow users to interact with iMessage easily, without having to learn AppleScript or Objective-C to access the “Private API” on macOS. The second step was creating “listeners” to trigger events that the app could emit to its clients such as new messages, group updates, and more. These were the building blocks that enabled us to create clients to interact with iMessage at a high level. Thus, BlueBubbles was born.

But I didn’t stop there. I took it a step further and added support for registering webhooks with the app, so that users could easily integrate with the events the app emits. This is the foundation for the rest of this post.

Shout out to our contributors who have helped make this all possible!

Now, I will detail how I was able to create a Chat GPT bot for iMessage, using BlueBubbles. For this, I could have written my own simple HTTP server, and written a bunch of custom code to handle the webhooks, API calls, and responses. Instead, I opted to utilize an existing project called n8n, which allowed me to build a workflow using a nice UI, webhook integration, and some pre-existing “nodes”.

My goal here was to create a bot that would respond to specific commands, within specific chats.

Pre-requisites

Here is what you’ll need to replicate this project:

  • A macOS device (virtual or physical) with iMessage support
  • BlueBubbles installed on the macOS device
  • n8n install on the macOS device or on the same network
  • An OpenAI (Chat GPT) API Key

n8n Workflow Template

Luckily for you all, I’ve created a simple “template” for n8n that you can import into your n8n Desktop instance as a guide.

The AppleScript version will be the “default” as the Private API version requires some additional setup on macOS, but enables subjects, replies, faster sending, send effects, and more.

Once imported, it should look like this:

Building a ChatGPT Bot for iMessage Using BlueBubbles (4)

The basic flow is as follows:

Wait for a new message -> Check if the message is a “command” -> Query Chat GPT for a response -> Send a text back to the chat

You’ll see this workflow is made up of 6 nodes. I will explain what each one of them does:

  • Wait for BlueBubbles Message: This node creates a webhook URL (provided by n8n), and waits for a message to be POST’d to it.
  • Check Command: This node checks to make sure the message that was sent is a “command message”. In this case, starting with ! .
  • Check Chat: This node checks to make sure the message was sent in a “whitelisted” chat. I don’t want the bot to be active for all my chats…
  • Get Query: This node simply strips the ! that the message started with.
  • OpenAI: This node sends the query to the Chat GPT API, and gets a response to the query.
  • Send Text: This node sends the Chat GPT response back to the chat the message came from.

Modifying the Command

If you want to modify the command (to trigger the bot), double-click on the Check Command node, and modify the condition.

The default just requires the message to start with an exclamation character as shown below. But you can really make it whatever you want.
For instance !gpt . Removing the Check Command node will send any message to the Chat GPT (assuming the other checks pass).

Building a ChatGPT Bot for iMessage Using BlueBubbles (5)

Note, if you change the command, you will also need to edit the Get Query node to account for the new command.

Whitelisting Chats

The Check Chat node handles chat whitelisting. That’s to say, I don’t want this bot to react to messages coming from all my chats, I just want it to react to messages coming from these specific chats.

By double-clicking the node, you can use the Add Condition button to add a String condition, checking if the following expression Equals a value

{{ $node["Wait for BlueBubbles Message"].json.body.data.chats[0].guid }}

The value that the expression should equal looks like this for DMs, iMessage;-;+1<address> or iMessage;+;chat<id> for group chats.

If you do not know what the Chat GUID is, skip ahead to Configuring the Workflow with BlueBubbles to test the workflow webhook and get a sample event from the chat you want to use the bot in.

It should look similar to this:

Building a ChatGPT Bot for iMessage Using BlueBubbles (6)

Configuring your OpenAI (Chat GPT) API Key

If you do not have a Chat GPT API key, you can purchase a plan via the OpenAI website.

To configure your API key, double-click the OpenAI node, and click the pencil icon next to the Credential to connect with field. Then just paste your key into the provided field. You do not need to enter an Organization ID . It should look like this

Building a ChatGPT Bot for iMessage Using BlueBubbles (7)

Configuring the Response Text

Lastly, you will need to setup the HTTP request to send a text back to the chat that the message originated from.

Double click the Send Text node to configure it. For the URL field, you will need to replace the IP address and port with the IP address (or localhostif running on your macOS device). If you are not running n8n on your macOS device, and you do not know your IP address, you can follow these steps to get it:

  1. Open Terminal on your macOS device
  2. Type ifconfig and hit enter
  3. Look for a section labeled en0 (or similar)
  4. Wihtin that section look for a line prefixed with inet . The value following inet should be your local IP address

Your IP address should look similar to 192.168.50.x or 10.0.0.x for certain home networks.

Next, you will need to configure your BlueBubbles server credentials. Click on the pencil icon next to the Credential for Query Auth field. For the Value field, enter your BlueBubbles Server password.

Everything else should be able to be left untouched.

Once your n8n workflow is complete, you will need to configure it with BlueBubbles. Open the BlueBubbles Server on your macOS device

Navigate through the walkthrough if you haven’t already. You do not need to set up the Google Firebase configuration.

Getting your Webhook URL from n8n

To get your Webhook URL from n8n, double click on the Wait for BlueBubbles Message node and copy the Test URL it provides.

Building a ChatGPT Bot for iMessage Using BlueBubbles (8)

Note, for production use, copy the Production URL

Click on the API & Webhooks tab. Then click the Manage drop down, selecting Add Webhook from the list of options.

Adding the Webhook to BlueBubbles

In the Add Webhook popup, paste your n8n webhook URL into the URL field.

Next, select the event subscriptions that you want your webhook to be triggered for. For this example, just select New Messages

Building a ChatGPT Bot for iMessage Using BlueBubbles (9)

Lastly, save the webhook configuration.

Testing your n8n Workflow

Now that the webhook configuration is saved, go back to n8n and click on the Execute Workflow button.

The workflow should run, waiting for a message to be sent.

Send a message in your desired chat (it doesn’t need to be a command). If everything is configured correctly, you should see a green check show next to the Wait for BlueBubbles Message node.

If you do not see the green checkmark, check your BlueBubbles server for any errors regarding a failed Webhook.

Now that you know your workflow receives the webhook, you can send a command message to your desired chat to make sure the rest of the workflow is operating properly.

If you have not whitelisted chats at this point, I advise looking at the output data for the Wait for BlueBubbles node, and grabbing the Chat GUID from the data.

Building a ChatGPT Bot for iMessage Using BlueBubbles (10)

If everything is working in your test environment. Re-configure the BlueBubbles Webhook with the n8n Production URL .

As you can imagine, the results are exactly what you’d expect!

Building a ChatGPT Bot for iMessage Using BlueBubbles (11)
Building a ChatGPT Bot for iMessage Using BlueBubbles (12)
Building a ChatGPT Bot for iMessage Using BlueBubbles (13)

This is just one example of a bot you can create for your iMessage chats. The possibilities are seemingly endless, and I’m sure you can get other ideas from the numerous Discord bots that already exist.

I hope you all found this post informative and entertaining!

BlueBubbles is a free and open-source ecosystem of apps aimed to bring the iMessage experience to non-Apple devices! BlueBubbles is available on Android, PC, and the Web. All the source code can be found on our GitHub below:

You can find us on the Google Play Store.

We have a bunch of documentation on our help center here:

If you would like to support the project & contributors, head over to our website.

If you would like to join our Discord community to interact with users & devs (including myself), join here:

Credits: I am the maintainer of the BlueBubbles ecosystem

Building a ChatGPT Bot for iMessage Using BlueBubbles (2024)

FAQs

How do I integrate ChatGPT with iMessage? ›

How to enable ChatGPT integration with iMessage? In the Current Sender Names section, select an active purchase and in the Integrations section, activate ChatGPT. You will need to set your API Key and the Model that will be used to generate replies. For more tech info, check out our dev docs.

How do you use ChatGPT effectively? ›

How to use Chat GPT to revise effectively
  1. Summarise your notes. If you have tonnes of notes from class or you're not sure what the key points of a text are, ask Chat GPT to summarise it for you. ...
  2. Test yourself. ...
  3. Get creative. ...
  4. Take a break.

What is chat gpt3? ›

Chat GPT-3 is an artificial intelligence language model created by OpenAI. It can understand and generate natural language responses with a high degree of accuracy. This technology is based on the concept of Generative Pre-trained Transformer 3 (GPT-3), which is a deep learning model for natural language processing.

What is the function of ChatGPT? ›

What Can Chat GPT Do?
  • Natural Language Understanding. Chat GPT excels in understanding natural language. ...
  • Answering Questions. One of the primary uses of Chat GPT is answering questions. ...
  • Language Translation. ...
  • Content Generation. ...
  • Personal Assistant. ...
  • Improving Customer Support.
Jun 23, 2023

Is ChatGPT available on iPhone? ›

You can download OpenAI's popular chatbot from the App Store.

Can you set up automated messages on iMessage? ›

Yes, you can schedule a text message on iPhone, Android, PC, and desktop computers. But keep in mind, many text messaging scheduling features only send delayed texts.

How much does ChatGPT cost? ›

ChatGPT's subscription plan is called ChatGPT Plus, and it costs $20/month. The paid subscription model guarantees users general access even during peak times when the free version is at capacity, and offers ffaster response times.

Can ChatGPT be detected? ›

It is now completely possible for universities to detect ChatGPT and many other AI content generators. If work is submitted through a university's learning management system, such as Turnitin, AI, and plagiarism detection should happen.

Is it OK to use ChatGPT? ›

Yes, ChatGPT is safe to use. As an AI language model, ChatGPT is designed to provide helpful and informative responses to users while ensuring their safety and security.

What are the drawbacks of ChatGPT? ›

On the other hand, ChatGPT has many shortcomings, including its ability to generate biased responses, produce inaccurate information, inability to multitask, and more.

Is ChatGPT available for free? ›

If you're curious to try it out for yourself and see what all the fuss is about, you might be wondering if ChatGPT is free. In short, the answer is yes! But there's more. ChatGPT also offers users a paid premium version that unlocks additional features.

Can I train ChatGPT with my own data? ›

With your ChatGPT enabled website chatbot trained on your own data, you can you can easily deploy a ChatGPT powered customer service chatbot that will answer your visitor questions, can stay up to date with your latest content and articles, and can even escalate conversations to your agents when the right time comes.

What is the difference between ChatGPT and ChatGPT Plus? ›

ChatGPT Free is a basic version of the ChatGPT platform with limited access to features, while ChatGPT Plus is the subscription plan that provides users with enhanced access. ChatGPT Plus provides access to GPT-4, faster response times, and priority access to new features and improvements.

Does ChatGPT have an app? ›

ChatGPT app is now available for iPhone and Android phone. Users can download the app for free from the App Store and Google Play app store. The app allows users to access previous chats without an internet connection.

How do I add ChatGPT to my iPhone? ›

Step 1: Head over to the App Store and search for ChatGPT — The official app by OpenAI and select Get to download and install it on your iPhone. Step 2: Once it's installed, open the ChatGPT app. Step 3: The first time you use the ChatGPT app, you'll need to either sign into an existing account or create a new one.

How to use ChatGPT API in iOS? ›

How to use ChatGPT as a Siri shortcut on your iPhone or iPad
  1. Get API keys. Your first step is to get the necessary API keys from Open AI. ...
  2. Create new secret key. At the API keys screen, tap the button for Create new secret key. ...
  3. Get the shortcut. ...
  4. Add the API key. ...
  5. Run SiriGPT. ...
  6. Ask a question. ...
  7. Get the shortcut. ...
  8. Add the API key.
Apr 7, 2023

What is the best way to access ChatGPT on iPhone? ›

OpenAI has officially launched the ChatGPT app for iPhone. The app offers the best way to access the service on iPad and iPhone. The app syncs history across devices and also allows the users to use OpenAI's speech-to-text tool, based on Whisper, to enter the prompt using just their voice easily.

How to integrate ChatGPT in Xcode? ›

Integrating ChatGPT into Xcode using an Xcode Source Editor Extension that solves three specific problems:
  1. Code conversion. A command that converts a JSON document to a Swift struct.
  2. Code smells. We ask ChatGPT to try to identify things that can be improved in our source code.
  3. Code explanation. ...
  4. Unit testing. ...
  5. Regex.

References

Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated:

Views: 5800

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.