How to build an OpenAI assistant and connect it with Facebook Messenger (2 steps, no code)

Simple step-by-step guide on how to connect OpenAI assistants with your Facebook Page Messenger using Zapier.

Tomas Jancovic (It's AI Thomas)
Zapier AI Automation
6 min readFeb 22, 2024

--

by It's AI Thomas
Thursday 22 Feb 2024

In this guide, I'll walk you through creating your own AI assistant using OpenAI, training it on specific documents, and integrating it with Facebook Messenger through Zapier for automated customer interaction.

For those who enjoy watching videos rather than reading, I’ve also made a short video explaining and showing you everything that you need to know:

Step 1: Setting Up Your AI Assistant in OpenAI

The first step you will need to do is to build your own OpenAI GPT Assistant.

Don't worry, it's easier than you think — just follow the steps below.

Log into OpenAI

  • Start by logging into your OpenAI account by clicking “Log in” in the right upper corner here.

Navigate to Assistants

  • On the left panel, find and click on “Assistants”.
OpenaAI assistants

Create a New Assistant

  • Click on the green button “+Create” to create a new assistant.
Creating an OpenAI assistant

Configure Your Assistant

You will then be able to configure your OpenAI assistant to your needs.

  • Name: Give your assistant a descriptive name.
  • Instructions: Provide clear instructions on what the assistant is expected to do. Here is a prompt you can copy and paste:
Context: (You are a helpful customer support agent named Thomas. You answer all messages and inquiries that are sent to your Facebook Messenger.)
Your database for answering questions: (Use only the data from the files that were uploaded to your knowledge base.)
Details: (Don't reference the sources.)
  • Model: Select the GPT-4-turbo model for its advanced capabilities, including file interaction.
  • Tools: Ensure both tools are selected to enable file handling.
  • Upload Files: Upload documents that your assistant will use as a knowledge base. This could include business descriptions, FAQs, pricing, etc.
Tuning your OpenAI assistant with name, instructions, model, tools, and uploaded files as a knowledge base

It’s a little different to write effective instructions for your OpenAI GPT assistant, so if you want to know how to write them and leverage different parameters like prompt engineers do, get my totally FREE no-junk 3P framework here that will save you time and money.

Step 2: Integrating OpenAI Assistant with Facebook Messenger Using Zapier

In the second step, you will set up the automation on Zapier.

Set Up a Trigger

  • Choose Facebook Messenger as the trigger app.
  • Select the trigger event, typically “New Message sent to Page”.
Facebook Messenger trigger in Zapier
  • Connect your Facebook account using your credentials in the “Account” step in Zapier.
  • Select the relevant page from the drop-down menu in the “Trigger” section.
Choosing the Facebook Page in your Facebook Messenger automation in Zapier

Add a Delay (Optional But Worth It)

  • Consider adding a delay before the assistant responds to make interactions seem more human.
  • You can do this by adding the “Delay by Zapier” app as the first action after the trigger.
Delaying your Facebook Messenger chatbot in Zapier
  • Set up the time value and time units for how long you want to delay the OpenAI assistant to respond (Value = 10; Units = minutes).
Choosing the value and units when using Delay by Zapier
  • However, do not make the delay longer than 24 hours to ensure the automation runs smoothly without an error.

When using Zapier, you can only automate the answers to messages on your Facebook Messenger that have been received in the last 24 hours — otherwise you will get an error. I would recommend you to delay the action for 10–20 minutes so it looks more natural and you won't get an error. See the error example below.

Error example when using Delay by Zapier with Facebook Messenger

Initiate the Conversation

  • Use the ChatGPT app with the “Conversation with Assistant” event in Zapier.
Conversation with Assistant in ChatGPT in Zapier
  • Connect your OpenAI account if you have not already with an API key you generate on OpenAI.com (simply by copying and pasting it in Zapier).
  • Configure the message (prompt) that will be sent to the assistant, ensuring it includes the necessary instructions and parameters for generating a response.
  • Here is an example prompt you can copy and paste:
Answer the following inquiry: {Insert the "Message Text" dynamic variable from your trigger}
Prospect's name: {Insert the Sender First Name dynamic variable from your trigger}
Details: (The message must not be longer than 500 characters. At the end of the message, always leave this link: {Insert your CTA URL link like this: https://popupsland.com/book-a-demo/} and encourage them to get a totally free non-binding demo from one of our experts.)
  • Select the assistant you’ve created on OpenAI from the dropdown menu (the name of the assistant is the name you gave it when you were creating it on the OpenAI page).
Initiating the conversation with the OpenAI assistant in Zapier
  • You can leave all the next fields like “Assistant Name”, “Assistant Instructions”, “Model”, “Tools”, “New Files” and leave them blank.

This is because you have already set them up on OpenAI before. These fields are there if you want to create a new OpenAI assistant directly inside Zapier. For example, if you leave the “Assistant” name blank and you don't choose any assistant from your OpenAI account, Zapier will use these fields to always create a new assistant for you.

  • The In the “Conversation ID”, choose “Sender Psid” dynamic variable from your trigger.

If provided, this unique value will allow the assistant to continue a conversation from previous messages. Use something that won’t change over the course of a conversation (like a customer support ticket ID.) If blank, the assistant will not remember this conversation going forward.

Setting up your Conversation ID in your OpenAI assistant chatbot

Send the Response Back via Facebook Messenger

  • Choose Facebook Messenger as the action app, and choose “Send Message from Page” as your event.
Sending OpenAI assistant message using the Facebook Messenger app in Zapier
  • In the “Account” section, make sure your Facebook Messenger account is connected (it should as you have done it already in the trigger).
  • Next, in the “Page” field, choose the name of your Facebook page.
  • In the “Recipient ID” field, choose the “Sender Psid” dynamic variable from your trigger.
  • Lastly, in the “Text” field, insert your dynamic variable from your Conversation With Assistant action called “Full Response”.
Choosing the Page name, Recipient ID, and the message for your OpenAI assistant

Test Your Automation

  • Ensure to test each step of your Zap to confirm that the automation works as expected.
  • Once satisfied, name your Zap for easy identification and publish it.
  • Congratulations, you are done!
Final OpenAI assistant integration with your Facebook Messenger using Zapier

😉➡️ My resources that will help you save time, money, and headaches: https://bit.ly/itsaithomas

--

--

Tomas Jancovic (It's AI Thomas)
Zapier AI Automation

👋 Data analyst who also helps you automate your business processes (with Zapier and AI)! My YouTube: https://www.youtube.com/@itsaithomas/videos