1. Integrations
  2. Fitness Instructor

Integrations

Fitness Instructor

Introduction

By the end of this tutorial, you'll be able to build a personal fitness instructor. This instructor will help you with the following:

  • Setting a goal that you want to achieve.
  • Providing a training program on a schedule that fits your needs to help you reach your goal.
  • Reminding you every week of your training program for the week.
  • Reminding you on the day of training about the program for that specific day.

Setting Up Your Org

We assume that you are already a Stubber user with your own organization. Start on Manage in the contacts section.

In the video below, we add a mobile contactpoint to our contact. This is required since the fitness instructor will communicate with you via WhatsApp.

Add mobile contactpoint to contact

Add your cellphone number as a mobile contactpoint to your own contact.

Building the Template

Navigate to the Editor app and create a new template. You can name it whatever you like; we call our template "Fitness Instructor".

We navigate to Editor by selecting the app switcher at the top right.

Go to editor and create a new template

Adding an Initial State

Each template requires an initial state. This is the state that each stub created for the template will start in and is called the busy_start_state. The first state you create in a template is automatically set as the busy_start_state.

Add busy start state

You can see that the busy_start_state is blue, indicating that it is special, similar to the done state, as normal states are white.

Adding an Action to Start a Chat

Now that we have the initial state that stubs will start in, let's add the action that will kick off the chat with your personal fitness instructor.

Add start action and link

In the video above, we add the start_chat action from the Actions library. This action already contains the necessary fields, tasks, and notifications for it to function. You can browse these items in the Editor, as shown in the video above.

Linking a state to an action makes that action available to be run when a stub is in that state. So, we have now made the start_chat action available in the chat-start-pending state.

Setting Up the Rest of the Template

With the initial states and the start action set up, let's set up the rest of the template.

We first add the chat-active state and then all the actions that the fitness instructor will be able to run.

Here is a list of these action names:

  • set_user_goal: The assistant calls this action to set the user's goal. It is stored in the stub data so that it can be accessed again later.
  • set_user_schedule: The assistant sets the schedule to specify which days of the week the user is available to train. This might be, e.g., Monday 1-3pm, Tuesday 3-4pm, etc.
  • build_training_program: Given the user's goal and schedule, the assistant builds a training program that fits the user.
  • schedule_weekly_sunday_reminder: The assistant schedules the weekly reminder. This schedules another action to be run via Heimdall every Sunday. The other action that is scheduled is the log_weekly_reminder action.
  • log_weekly_reminder: This is the action that is scheduled to run automatically every Sunday by the schedule_weekly_sunday_reminder action.

Set up rest of template

Next, we add the system actions. These actions override normal Stubber functionality.

Here is a list of the system actions that we add:

  • _update_from_whatsapp: This action runs when a WhatsApp message is received in a Stubber interaction. It contains the message that the user sent, as well as some additional data from WhatsApp.
  • _update: This action can be run manually on Stubber at any time. Here, we use it to test the fitness instructor without having to use WhatsApp. This allows for faster iteration.
  • _update_from_chat_assistant_task: The AI assistant runs this action with its response when a gpt_chat_task task on a previous action executes successfully. The AI assistant can also choose to run another action instead of this one when appropriate.

Set up the system actions

In the video above, it can be seen that the system actions are not linked to any states. This is okay for system actions since they inherit their links to the special _all state from their parent template. The _all state allows an action to be run from any state.

For example, the _update_from_whatsapp action is overridden here to interact with the AI assistant whenever it receives an update from WhatsApp. More about these system actions can be found here.

Create a Stub and Start a Chat

To try out the fitness instructor, we need to create a stub.

Create stub

Once you've opened the stub created in the video above, you can start the chat by clicking the Start chat button.

Start chat

You should see a message from the AI assistant.

Stub with active chat

Notice that the state of the action changed to

chat-active
.

You can now interact and speak to your personal fitness instructor by sending messages with the Update stub action.

Testing the Fitness Instructor

Example interaction with assistant

Send a message to the assistant and see how it responds.
Above, we tell it our goal, so we should expect to see the

set_user_goal
action run.

Read the below from the bottom up, as the newest messages are at the top of the stub.

Set User Goal Action Ran By AI

The assistant automatically chose to run this Stubber action and automatically filled in the fields for us.

In order for an action to be run by the AI assistant, AI Function Calling must be enabled.

Setting Your Schedule

Sending another message to the assistant, we can tell it our general availability.

Telling the assistant our schedule

As you can see, the assistant again automatically chose to run the

set_user_schedule
action.

Generating a Training Program

Since our prompts.ai_instructions say that the assistant needs to find out the user's age and other info, you will see it ask for this information before it can generate a training program.

Providing missing info and generating training program

Once we've provided the info it needs, the assistant will generate a training program for us.

You will see the assistant ran these actions:

  • build_training_program
  • schedule_weekly_sunday_reminder

Finally, the last

_update_from_chat_assistant_task
action was run, which is the AI assistant's response to the user.