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.
- Provide a training program on a schedule that fits you to help you reach your goal.
- Remind you every week of your training program for the week.
- Remind you on the day of training of the training program for that specific day.
Setting up your org
We assume that you are already a Stubber user with your own org. Start on Manage on 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 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 want, we call our template "Fitness Instructor".
We navigate to Editor by selecting the app switcher at the top right.
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 that you create on a
template is automatically set as the busy_start_state
.
You can see that the busy_start_state
is blue, this indicates 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, lets add the action
that will kick off the chat with
your personal fitness instructor.
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 Editor
as shown in
the video above.
The linking of a state to an action makes that action available to be ran 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 us 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 goal of the user. It is stored in the stub data such that it can be accessed again at a later time.set_user_schedule
: The assistant sets the schedule to specify which days in a week the user is available to train. This might be eg. 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 ran via Heimdall every Sunday. The other action that is scheduled is thelog_weekly_reminder
action.log_weekly_reminder
: This is the action that is scheduled to run automatically every Sunday by theschedule_weekly_sunday_reminder
action.
Next we add the system actions, these actions override normal Stubber functionality.
Here is a list of the system action that we add:
_update_from_whatsapp
: This action runs when aWhatsapp
message is received in a Stubber interaction. It contains the message that the user sent, as well as some additional data fromWhatsapp
._update
: This action can be ran manually on Stubber at any time. Here we use it to test out the fitness intstructor without having to useWhatsapp
. This allows for faster iteration._update_from_chat_assistant_task
: The AI assistant runs this action with its response when agpt_chat_task
task on a previous action executes successfully. The AI assistant can also choose to run another action instead of this action when appropriate.
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 ran from any state.
The _update_from_whatsapp
action, for example, is here overwritten to interact with the AI assistant whenever
it receives an update from Whatsapp
. More about these system actions can be found here
Create stub and start chat
To try out the fitness instructor, we need to create a stub.
Once you've opened the stub we created in the video above, you can start the chat by clicking the Start chat
button.
You should see a message from the AI assistant.
Notice that the
state
of the action changed tochat-active.
You can now interact and speak to your personal fitness instructor by sending messages with the Update stub
action.
Testing the Fitness Instructor
Send a message to the assistant and see how it responds.
Above we tell it our goal, so we should expect to see the
Read the below from the bottom up, as the newest messages are at the top of the stub.
The assistant automatically chose to run this Stubber action, and automatically filled in the fields for us.
In order for an an action to be ran 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.
As you can see, the assistant again automatically chose to run the
Generating a training program
Since our prompts.ai_instructions
says 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.
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