Managing State

Using a simple storage mechanism you can keep track of state. Data is stored on a thread level and can be accessed even weeks after the first conversation took place.

(async payload => {

  // Get the current count, or 0
  let count = await state.get('count') || 0

  // Save the current count
  await state.save('count', count + 1 )

  // Show or speak the current count
  return new Message(`Count is ${count}`)
})

Storing data

(async payload => {

  await state.save('watched', {
    season: 1,
    episode: 2,
    serie: 'game-of-thrones'
  })
})

Retrieving data

(async payload => {

  // Could be null if not found
  const data = await state.get('watched')
})

Removing

(async payload => {
  await store.remove('watched')
})