KB112: The People Builder API


Use on a website

After you Publish your People Builder module, you use Get Embed Code to get a small snippet of html code that you place in your own website where you want your module to appear. In many cases the module is completely self-sufficient. For example a Slideshow module can be started and stopped using the navigation bar. Likewise, an Agent module can automatically greet the user on arrival to a page. You can also use JavaScript to control a module. This is especially useful with the Agent module. You can use the Messages tab to create messages, and you can trigger then using events on your page.

A typical embed tag for an Agent module looks like this:

<script src="https://www.mediasemantics.com/agent.min.js"></script>
<div id="myDiv" style="width:250px; height:200px;"></div>
<script>var myAgent; document.addEventListener("DOMContentLoaded", function() {myAgent = MSAgentModule.setupDiv("myDiv", "123456", "12345678")})</script>

You can invoke the module's API using the methods shown in the Agent preview pane. For example to trigger a message, you can use html such as:

<a href="javascript:test()">test</a>
<script>
function test() {
    myAgent.play("Message 1");
}
</script>

You can also stop a message with the stop() method.

An optional fourth parameter to setupDiv() is a parameters object that you can use to override several default behaviors. For example you can override the default module "fade in" behavior as follows:

MSAgentModule.setupDiv("myDiv", "123456", "12345678", {fade:false})})

You can register one or more event handlers to react to events in your module. Event handlers hould be attached to your containing div ('myDiv' in this case).

One important event is "moduleLoaded", which fires when enough resources have been loaded to begin showing your module. The event fires right before the contents of the div become visible and indicates that the module is ready to receive play() commands.

<script>
   document.getElementById("myDiv").addEventListener("moduleLoaded", function() {
      console.log("module loaded and about to become visible");
    });
</script>

Use in an iframe

The Get Embed Code screen also lets you get a URL for insertion in an iframe. This option is availabe for all modules, and is often used to insert a module into a content authoring tool. There is no API available when embedding a module using an iframe.


Use in React

The Agent module also has a React embed code using the npm component react-embodied-agent. The React embed code looks like this:

<ReactEmbodiedAgent ref={this.myAgentRef} style={{width:"250px", height:"200px"}} userid="12345678" moduleid="12345678" />

The parameters userid and moduleid are required, but will differ from the values shown above. You can also use the parameters described in this document. For example to make the module initially invisible, you would use:

<ReactEmbodiedAgent ref={this.myAgentRef} style={{width:"250px", height:"200px"}} userid="12345678" moduleid="12345678" 
    visible={false} />

Methods are available using the React "ref" syntax. For example to call play() you might use:

myAgentRef.current.play("Intro");

Finally, the events described in this document are available with the prefix "on" using the standard React syntax:

<ReactEmbodiedAgent ref={this.myAgentRef} style={{width:"250px", height:"200px"}} userid="12345678" moduleid="12345678" 
    onModuleLoaded={ () => console.log("module loaded") } />

API Common to all modules


Parameters

fadeIf true, the module will fade to visible right after the moduleLoaded event. Defaults to true.
visibleIf false, the module will be initially invisible, and you will need to use the show() or fadeIn() API to show it. Defaults to true.
identityOverrides the identity parameter of the module. Possible values are 'session', 'device', 'userid'. This can be useful if the user is known to have opted in or out of persistent cookies, which are used with the 'device' setting.
enduseridIdentity of the user, typically from a login. If not specified then an anonymous identity is generated.
pageOptional string that identifies the page the module is located on. The same Agent or Chatbot module may be placed on several pages of a site, and this parameter can help make the agent more context-sensitive.
preloadIf true, the module will attempt to preload resources for faster operation. Defaults to true.
idleTypeOptional string that specifies which "idle" routine to select from the character's repertoire. Stock characters normally only define one idle called "normal". You can use "none" to forgo any idle behavior. Defaults to "normal".
swayYou can use this to turn off the "sway" behavior on HD characters. Defaults to true.
breathYou can use this to turn off the "breath" behavior on HD characters. Defaults to true.

Methods

cleanup()You can clear the containing div or replace it with other content at any time. However it is best to call cleanup() on the instance before doing so. This gives the module a chance to stop playing any audio and release any resources. You do not need to invoke cleanup() if your entire page is being replaced - only do so in the case where the contents of the div will be replaced while the page remains visible, such as with a single-page app.
volume()Returns the volume of the module as a number between 0 and 1. Defaults to 1.
setVolume(n)Sets the volume of the module. The value 'n' is a number between 0 and 1.
pauseStartup()Pauses the startup sequence when called during moduleLoaded event processing, so you can do any additional loading, set any variables, etc.
resumeStartup()Resumes a paused startup.
overrideIdentity(value)Overrides the module's identity setting. Typically used to immediately respect the user's request to change whether persistent cookies are stored. Use 'session' to clear any cookies created by the module.
visible()Returns true if the module is visible.
hide()Hides the module.
show()Shows the module.
fadeOut()Fades out the module.
fadeIn()Fades in the module.
preloading()Returns true if the module is currently preloading material.
setIdleType()Allows the idleType parameter to be changed dynamically.
scriptFromText()Returns an array of {do, say} records from a paragraph of text.

Events

moduleLoadedDispatched by all modules as soon as all critical media has loaded and the module is about to become visible (normally with a fade).
closedCaptionDispatched at the point where a line in a message is spoken. The 'detail' field of the event contains the transcript of the line, for use in external closed captioning.
embeddedCommandDispatched when a [cmd] tag is encountered in the script. Parameters can be passed as an object in the 'detail' field. For example the tag [cmd a="1" b="2"] results in a detail object {a:"1", b:"2"}.
scriptCommandDispatched when a Command high-level action is encountered in the script. You will find this under the And Misc menu. An application-specific string is passed in the 'detail' field.
preloadCompleteDispatched by all modules when preloading activity is complete.

API specific to Agent Module


Methods

play(message) If the Agent is idle, begin playing the given message. If it is already playing a message, then add it to the message queue. The Agent will keep playing messages from the queue until the queue becomes empty, or until the stop() API is called. Messages are specified by name - this is the same name as you will see in People Builder, e.g. "Message 1".
stop() Has no effect if the Agent is idle. If the Agent is playing a message, then it smoothly stops the current message. The queue is immediately emptied on a stop() so that no further messages will play when the smooth stop is complete. To perform a smooth stop, any currently-playing animation (such as a head turn or a gesture) will complete, and then the character will return to the rest position. There is also a ramp-down of the audio. In some cases it can take up to a second for the smooth stop to occur. In order to be notified when the character is truly idle, you can listen to the playComplete event. Alternatively, if you want the character to stop what it is doing and play a different message, you can invoke stop() followed by a new play(). In this case, the stop() immediately clears the queue() and begins the smooth stop. When the stop is complete, the queued message begins to play.
dynamicPlay(object)

This API is rate-limited - please see the Account tab and the faqs page for more information. This API works just like play(), except that the details are passed in using a parameter object. The fields of the object mimic the controls available in the Builder.

doIf specified, the given animation is played along with any audio. The values for this field are the same as the animation name shown in the Builder, but all lower-case and with spaces turned to dashes. For example, to play the animation "Look Up Right" you would use an object {do:"look-up-right"}.
sayIf specified, this forms the text to be spoken using Text-to-Speech. The text is always spoken in the character's voice, as assigned in the Builder's Appearance tab under the Character parameters. A 256 character limit applies to the say field, however multiple dynamicPlay() calls can be invoked to queue up a longer piece of text. For more information on this limit and how to overcome it, see KB116.

Example:

myAgent.dynamicPlay({do:"look-up-right", say:"Let's take a look over here."});
playing()Returns true if the Agent is currently playing a message using play() or dynamicPlay(), or false if it is idle.
preloadPlay()Like play() but simply causes the resources for the play() to be downloaded and cached locally.
preloadDynamicPlay()Like dynamicPlay() but simply causes the resources for the dynamicPlay() to be downloaded and cached locally.

Events

playCompleteDispatched as soon as the play() or dynamicPlay() is complete, any play queue is empty, and the character has returned to the idle position.

API specific to Chatbot Module


Methods

reply(input) The module runs the input through the Mind, then speaks the resulting text, or plays the resulting script.
stop() This will smoothly stop a reply.

Events

preReplyDispatched when the user submits a new input, prior to sending that input to the Mind. The input is passed by reference as the "text" field of the parameter object, and can be altered by JavaScript code. The fields "retract" and "assert" can also be filled in with additional predicates to be retracted and/or asserted.
postReplyDispatched after the mind returns a new output, but prior to playing that output. The input is passed by reference as the "text" field of the parameter object, and can be altered by JavaScript code.

API specific to Slideshow


Parameters

playingIndicates whether the module should begin in the "playing" state. Default to false. This parameter should only be used when you know that audio context has been unlocked for the web page.
slideIf specified, provides the 1-based index of the initial slide. If none specified then the module begins on the first slide.
stepIf specified, provides the 1-based index of the initial step in the initial slide.
roundSimilar to slide but used in SoftSkills modules.

Methods

slide() or slide(n)With no arguments, returns the 1-based slide index for the current slide. With an argument, causes the slide to change instantly, with no fade.
round() or round(n)Similar to slide() but used in SoftSkills modules.
slides()Returns the total number of slides in the module.
rounds()Just like slides() but for SoftSkills modules.
step() or step(n)With no arguments, returns the 1-based step index for the current slide. With an argument, causes the step to change instantly, with no fade. Most slides have only one step, but some slides, such as Bullet slides, can use multiple steps to build the final visual.
steps()Returns the total number of steps in the current slide.
next()Advances instantly to next step or slide, and stops playing. Equivalent to pressing the Next button on the navigation bar.
previous()Moves back instantly to the previous step or slide, and stops playing. Equivalent to pressing the Previous button on the navigation bar.
first()Moves instantly to the first step of the first slide, and stops playing. Equivalent to pressing the First button on the navigation bar.
playing()Indicates whether the Slideshow is in the Playing state, which also corresponds to the enabled/disabled state of the Stop and Play buttons on the navigation bar.
play()Starts playing - equivalent to pressing the Play button on the navigation bar.
stop()Stops playing - equivalent to pressing the Stop button on the navigation bar.
enable(button)Overrides the enabled state of a navigation bar button in a Pressed event, such as nextPressed. The argument can be one of "play", "stop", "next", "previous", "first".
disable(button)Overrides the enabled state of a navigation bar button. The argument can be one of "play", "stop", "next", "previous", "first".
scoringSlides()Returns the number of scoring slides.
slidesAnswered()Returns the number of scoring slides that have been answered.
slidesAnsweredCorrectly()Returns the number of scoring slides that have been answered correctly.

Events

slideChangedIndicates that the slide has changed, either under the user's control via the navigation bar, or via the agent's control. Use the slide() method to determine the new slide number.
stepChangedIndicates that the step has changed, either under the user's control via the navigation bar, or via the agent's control. Use the step() method to determine the new step number.
variablesChangedIndicates that the variables have changed.
playingChangedIndicates that the "playing" state, as indicated by playing() has changed.
playPressedIndicates that the Play button has been pressed on the navigation bar.
stopPressedIndicates that the Stop button has been pressed on the navigation bar.
nextPressedIndicates that the Next button has been pressed on the navigation bar.
previousPressedIndicates that the Previous button has been pressed on the navigation bar.
firstPressedIndicates that the First button has been pressed on the navigation bar.





Copyright © 2025 Media Semantics, Inc. All rights reserved.
Comments? Write webmaster@mediasemantics.com.
See our privacy policy.