Introducing Poke - triggering CX changes from the cloud

Introducing Poke - triggering CX changes from the cloud

import useBaseUrl from ‘@docusaurus/useBaseUrl’

Today we are launching Poke, a new primitive available in Dragonfly. Poke enables the cloud to dynamically and in near real-time send signals and data to our mobile client applications. Client Applications can use Poke to perform a variety of tasks, like updating the UI with new information.

What is Poke?

Poke lets our mobile applications receive and take action to triggers sent by the backend cloud architecture. In the Maestro example above, the service that receives the streaming response from the LLM is able to send a Poke message to their client CX, the client CX is then able to pull data from FireFly and show the playlist as it’s being made to the customer. This provides a much more interactive and faster experience for our customer.

That experience can get even better over time, as the Maestro Team can update their contract to avoid the call to FireFly by providing the data needed in their Poke messages.

How can I integrate Poke?

Here are the 3 steps for integrating with Poke:

  1. Define your Poke data contract

  2. Receive and process your Pokes on the client

  3. Trigger your Pokes from the cloud

1. Define your Poke data contract

The Poke message contains 2 fields that are required and a third that is optional. The first field is customerID, we have to know who we are sending the message to. The second field is domain, we need to know what domain the data falls under. This field impacts which handler get invoked on the client. The third field is called data, and it’s defined by you. It can be undefined, a string or JSON. Your choice.

Let’s say you wanted to send a Poke when a playlist is updated. You could use this contract:

{
  customerId: 'ACUSTOMERID',
  domain: 'PlaylistLibraryUpdated',
}

Or, you want to send a Poke when a customer Likes a new song, you could use this:

{
  customerId: 'ACUSTOMERID',
  domain: 'CustomerLikes',
  data: ..., //Like data
}

2. Receive and process your Pokes on the client

The following code example shows how you will import and register to receive a Poke for a specific domain in a DragonFly page.

import { register } from '~/stores/Casting/PokeClient'

const pokeCleanUp = useRef<Promise<() => Promise<void>> | undefined>(undefined)

interface YourPokeInterface {
  entityMrn: string | undefined,
  /* Additional fields */
}

/**
 * Invoke this when and where you need to start receiving Pokes.
 */
const startPoke = useCallback(async (): Promise<void> => {
  pokeCleanUp.current = register(
    'CustomerLikes',
    (type, _data) => {
      if (_data !== undefined) {
        const parsedData: PlaylistLibraryPokeInterface | undefined =
          _data as unknown as YourPokeInterface
        // Now call your handler.
        handlePoke(parsedData)
      }
    },
  )
})

/**
 * Invoke when you no longer need to receive Pokes.
 */
const stopPoke = () : void => {
    pokeCleanUp.current?.then(cleanUp => {
      cleanUp()
    })
}

You should call startPoke as soon as you need to begin receiving them. Typically this will be either when entering a page or the customer has taken a specific action , e.g. hitting button. Similarly you should call stopPoke when the customer leaves a page, the customer has taken a specific action, or the Poke tells you “there’s no more”.

3. Trigger your Pokes from the cloud

The following code shows how you can trigger Poke using a javascript Lambda:

const FUNCTION = ''; /* The Poke Lambda ARN you need to call */

export const sendPoke = async (customerId, domain, data, lambdaClient) => {
  try {
    const invokeParams = {
      FunctionName: FUNCTION,
      InvocationType: "RequestResponse",
      Payload: JSON.stringify({ customerId: customerId, domain: domain, data: data }),
    };
    const invokeCommand = new InvokeCommand(invokeParams);
    const response = await lambdaClient.send(invokeCommand);
  } catch (error) {
    console.error(`Error invoking Lambda function: ${error}`);
    throw error;
  }
}

Send a poke when your cloud services know something happened that a client should or might want to react to.

4. Test

Now you’re ready to start testing your Poke integration!

Things to know

Poke is primarily designed for Amazon Music experience developers to deliver dynamic experiences with signals from the cloud. It can also be used to improve existing polling experiences like library and playlist synchronization.

Onboarding to develop a POC is as simple updating an allow list with your AWS account number(s). Reach out today to begin onboarding!

Is there a demo or POC?

The following video demonstrates side-by-side the difference between Maestro’s Poke integration (left) and current production (right) experience:

Am I limited to Poking at the Customer ID level?

Currently yes, but if you have a use-case we can either help you figure out how to use Poke appropriately at the Customer ID level or extend Poke to support other levels (i.e. ProfileID, PlaylistID, ASIN, etc).

How much data can I send?

Messages can be as large as 128KB. This is for the entire message, not just your data.