npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ask-utils/proactive-event

v3.11.0

Published

Alexa proactive event utilities

Downloads

73

Readme

ASK-Utils - Proactive event helpers

npm version License: MIT Maintainability Test Coverage Build Status logo

https://ask-utils.dev

Getting started

$ npm i -S @ask-utils/proactive-event

Usage

import { Client, MediaContent } from '@ask-utils/proactive-event'

// setup client
const clientSecret = 'XXXXXXXXXXXXXX'
const client = new Client({
  clientId: 'amzn1.application-oa2-client.XXXXXXXXX',
  clientSecret: 'XXXXXXXXXXXXXX',
  apiRegion: 'FE' // default: US
})
// configure event information
const PayloadBuilder = MediaContent.Available.PayloadFactory.init()
const parameters = PayloadBuilder
  .setMediaType('ALBUM')
  .setStartTime(moment('2019-03-11T10:05:58.561Z').toDate())
  .setDistributionMethod('AIR')
  .getParameter()
// configure localizedAttributes
const localizedAttributes = LocalizedAttributes.Factory.init()
  .putLocalizedAttribute('en-US', 'contentName', 'New CD')
  .putLocalizedAttribute('ja-JP', 'contentName', 'あたらしいCD')
  .getLocalizedAttributes()

// Call proactive event API
client.setEvent(parameters)
  .setRelevantAudience('Multicast')
  .setLocalizedAttributes(localizedAttributes)
  .requestEvent()
  .then(result => console.log(result))
  .catch(result => console.log(result))

// requested body
{
  "timestamp": "2019-03-14T06:19:23.625Z",
  "expiryTime": "2019-03-15T06:19:23.627Z",
  "event": {
    "name": "AMAZON.MediaContent.Available",
    "payload": {
      "availability": {
        "method": "AIR",
        "startTime": "2019-03-11T10:05:58.561Z"
      },
      "content": {
        "name": "localizedattribute:contentName",
        "contentType": "ALBUM"
      }
    }
  },
  "relevantAudience": {
    "type": "Multicast"
  },
  "referenceId": "9f96ac5e-b341-46bd-b137-6d3b1812ec1d",
  "localizedAttributes": [
    {
      "locale": "en-US",
      "contentName": "New CD"
    },
    {
      "locale": "ja-JP",
      "contentName": "あたらしいCD"
    }
  ]
}

Features

Client

We can easy to call the Proactive event API by the client.

import { Client } from '@ask-utils/proactive-event'

const clientSecret = 'XXXXXXXXXXXXXX'
const client = new Client({
  clientId: 'amzn1.application-oa2-client.XXXXXXXXX',
  clientSecret: 'XXXXXXXXXXXXXX',
  apiRegion: 'FE' // default: US
})

const payload = {
  availability: {
    method: "AIR",
    startTime: "2019-03-11T10:05:58.561Z"
  },
  content: {
    contentType: "ALBUM",
    name: "localizedattribute:contentName"
  }
}

client.setPayload(payload)
  .setEventName("AMAZON.MediaContent.Available")
  .setRelevantAudience("Multicast")
  .requestEvent()
  .then(result => console.log(result))
  .catch(result => console.log(result))

LocalizedAttributes Builder

We can easy to create LocalizedAttributes.

import { LocalizedAttributes } from '../../dist/index'

const AttributesBuilder = LocalizedAttributes.Factory.init()
  .putLocalizedAttribute('ja-JP', 'gameName', 'ポケモン')
  .putLocalizedAttribute('en-US', 'gameName', 'pokemon')
  .getLocalizedAttributes()

[
  { locale: 'ja-JP', gameName: 'ポケモン' },
  { locale: 'en-US', gameName: 'pokemon' }
]

Payload Builder

And we can easy to create request payload by the following builders.

import { Client, MediaContent } from '@ask-utils/proactive-event'

const clientSecret = 'XXXXXXXXXXXXXX'
const client = new Client({
  clientId: 'amzn1.application-oa2-client.XXXXXXXXX',
  clientSecret: 'XXXXXXXXXXXXXX',
  apiRegion: 'FE' // default: US
})

const PayloadBuilder = MediaContent.Available.PayloadFactory.init()
PayloadBuilder
  .setMediaType('ALBUM')
  .setStartTime(moment('2019-03-11T10:05:58.561Z').toDate())
  .setDistributionMethod('AIR')
  .getParameter()

client.setEvent(PayloadBuilder.getParameter())
  .setRelevantAudience("Multicast")
  .requestEvent()
  .then(result => console.log(result))
  .catch(result => console.log(result))

AMAZON.MediaContent.Available

import { MediaContent } from '@ask-utils/proactive-event'

const PayloadBuilder = MediaContent.Available.PayloadFactory.init()
PayloadBuilder
  .setMediaType('ALBUM')
  .setStartTime(moment('2019-03-11T10:05:58.561Z').toDate())
  .setDistributionMethod('AIR')
  .getParameter()

{
  "name": "AMAZON.MediaContent.Available",
  "payload": {
    "availability": {
      "method": "AIR",
      "startTime": "2019-03-11T10:05:58.561Z"
    },
    "content": {
      "contentType": "ALBUM",
      "name": "localizedattribute:contentName"
    }
  }
}

AMAZON.TrashCollectionAlert.Activated

import { TrashCollectionAlert } from '@ask-utils/proactive-event'

const PayloadBuilder = TrashCollectionAlert.Activated.PayloadFactory.init()
PayloadBuilder
  .setCollectionDayOfWeek('MONDAY')
  .addGarbageType('BOTTLES')
  .addGarbageType('BULKY')
  .addGarbageType('CANS')
  .getParameter()

{
  "name": "AMAZON.TrashCollectionAlert.Activated",
  "payload": {
    "alert": {
      "collectionDayOfWeek": "MONDAY",
      "garbageTypes": [
        "BOTTLES",
        'BULKY',
        'CANS'
      ]
    }
  }
}

AMAZON.WeatherAlert.Activated

import { WeatherAlert } from '@ask-utils/proactive-event'

const PayloadBuilder = WeatherAlert.Activated.PayloadFactory.init()
PayloadBuilder
  .setAlertType('HURRICANE')
  .setAlertSource('example source')
  .getParameter()

{
  "name": "AMAZON.WeatherAlert.Activated",
  "payload": {
    "weatherAlert": {
      "source": "example source",
      "alertType": "HURRICANE"
    }
  }
}

AMAZON.MessageAlert.Activated

import { MessageAlert } from '@ask-utils/proactive-event'
const PayloadBuilder = MessageAlert.Activated.PayloadFactory.init()

PayloadBuilder.setMessageCreator('john')
    .setMessageCount(1)
    .setMessageStatus('FLAGGED')
    .getParameter()

{
  "name": "AMAZON.MessageAlert.Activated",
  "payload": {
    "messageGroup": {
      "count": 1,
      "creator": {
        "name": "john"
      }
    },
    "state": {
      "status": "FLAGGED"
    }
  }
}

AMAZON.Occasion.Updated

import { Occasion } from '@ask-utils/proactive-event'
const PayloadBuilder = Occasion.Updated.PayloadFactory.init()

PayloadBuilder
  .setBookingTime(new Date())
  .setOccasionType('APPOINTMENT')
  .setSubject('subject')
  .getParameter()

{
  "name": "AMAZON.Occasion.Updated",
  "payload": {
    "state": {
      "confirmationStatus": "CONFIRMED"
    },
    "occasion": {
      "occasionType": "APPOINTMENT",
      "subject": "subject",
      "provider": {
        "name": "localizedattribute:providerName"
      },
      "bookingTime": "2019-03-14T04:24:15.097Z",
      "broker": {
        "name": "localizedattribute:brokerName"
      }
    }
  }
}

AMAZON.OrderStatus.Updated

import { OrderStatus } from '@ask-utils/proactive-event'
const PayloadBuilder = OrderStatus.Updated.PayloadFactory.init()

PayloadBuilder
  .setEnterTimestamp(new Date())
  .setExpectedArrival(new Date())
  .setOrderStatus('ORDER_DELIVERED')
  .getParameter()

{
  "name": "AMAZON.OrderStatus.Updated",
  "payload": {
    "state": {
      "status": "ORDER_DELIVERED",
      "enterTimestamp": "2019-03-14T04:25:46.031Z",
      "deliveryDetails": {
        "expectedArrival": "2019-03-14T04:25:46.033Z"
      }
    },
    "order": {
      "seller": {
        "name": "localizedattribute:sellerName"
      }
    }
  }
}

AMAZON.SocialGameInvite.Available

import { SocialGameInvite } from '@ask-utils/proactive-event'
const PayloadBuilder = SocialGameInvite.Available.PayloadFactory.init()

PayloadBuilder.setGameName('Game')
  .setGameOfferName('MATCH')
  .setInviteType('CHALLENGE')
  .setRelationshipToInvitee('FRIEND')
  .getParameter()

{
  "name": "AMAZON.SocialGameInvite.Available",
  "payload": {
    "invite": {
      "inviteType": "CHALLENGE",
      "inviter": {
        "name": ""
      },
      "relationshipToInvitee": "FRIEND"
    },
    "game": {
      "offer": "MATCH",
      "name": "Game"
    }
  }
}

AMAZON.SportsEvent.Updated

import { SportsEvent } from '@ask-utils/proactive-event'

SportsEvent.Updated.PayloadFactory.init()
  .setAwayTeamStatistic('away', 10)
  .setHomeTeamStatistic('home', 0)
  .getParameter()

{
  "name": "AMAZON.SportsEvent.Updated",
  "payload": {
    "sportsEvent": {
      "eventLeague": {
        "name": "localizedattribute:eventLeagueName"
      },
      "homeTeamStatistic": {
        "team": {
          "name": "home"
        },
        "score": 0
      },
      "awayTeamStatistic": {
        "team": {
          "name": "away"
        },
        "score": 10
      }
    }
  }
}

development

$ git clone [email protected]:ask-utils/proactive-event.git
$ cd proactive-event
$ npm i

test

$ npm test

Lint

$ npm run lint

or

$ npm run lint -- --fix

History

-> Release Note

Contributors

|Name|Version| |:--|:--| |||