Skip to main content

Events

Events are a way to be informed of the actions taken by the assistant as requested by user prompts. When the user has prompted the assistant to do something, the AI will trigger an action and respond with an event. For example, you can ask the assistant to play music, or to stop the navigation, and more advanced cases like changing the temperature in the car. Mapbox continues to build out more events and refine the existing ones.

There are several MapGPT events that can be observed with the SDK using the API observeMapGptEvents:

  • Activated: The event indicates that a new conversation with the assistant has been activated.
  • PlayingMusic: The event indicates that the requested music is now playing.
  • PausedMusic: The event indicates that the current music which was playing has now been paused.
  • ResumedMusic: The event indicates that the current music which was paused has now been resumed.
  • StartedNavigation: The event indicates that navigation has started to a destination of your choice.
  • StoppedNavigation: The event indicates that navigation has stopped.
  • SetHvac: The event indicates that the assistant has acknowledged to update the temperature of the vehicle.

Upon visual rendering of data by the assistant in form of cards, the end user can click on the card to do certain actions. In cases, where the data displayed on the UI represents a custom payload, a tap by the user on the card can be observed using observeMapGptCardEvents.

Observing events

See the Events API guide for more information on how to observe other events offered by the SDK. There are many data points to observe while navigating to a destination.

observeMapGptEvents

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeMapGptEvents()
.collect { /* DashMapGptEvent */ event ->
// Do something with the MapGptEvent
processMapGptEvents(event)
}
}
}
}

fun processMapGptEvents(event: DashMapGptEvent) {
when (event) {
is DashMapGptEvent.Activated ->
Toast.makeText(
this,
"New conversation with the assistant has started",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.PlayingMusic ->
Toast.makeText(
this,
"App is playing the song with track identified by ${event.trackId}",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.PausedMusic ->
Toast.makeText(
this,
"App has paused the music that was playing",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.ResumedMusic ->
Toast.makeText(
this,
"App has resumed the music that was paused",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.StartedNavigation ->
Toast.makeText(
this,
"App has started navigation to your destination",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.StoppedNavigation ->
Toast.makeText(
this,
"App has stopped navigation",
Toast.LENGTH_SHORT
).show()
is DashMapGptEvent.SetHvac ->
Toast.makeText(
this,
"App has set the vehicle temperature to ${event.temperature} ${event.unit}",
Toast.LENGTH_SHORT
).show()
}
}
}

observeMapGptCardEvents

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeMapGptCardEvents()
.collect { /* DashMapGptCardEvent */ event ->
// Do something with the DashMapGptCardEvent
processMapGptCardEvents(event)
}
}
}
}

fun processMapGptCardEvents(event: DashMapGptCardEvent) {
when (event) {
is DashMapGptCardEvent.OnMapGptCardClicked ->
Toast.makeText(
this,
"User tapped on the card rendering data identified by ${event.payload}",
Toast.LENGTH_SHORT
).show()
}
}
}
Was this page helpful?