LoginSignup
0
0

More than 3 years have passed since last update.

スキルのアップデート情報を起動時にお知らせする方法

Last updated at Posted at 2020-07-06

はじめに

スキル内で、スキルのアップデート情報をユーザにお知らせするやり方についてです。

スマホのAlexaアプリやブラウザでは、更新情報が確認できます。
しかし、それらを開いてまで確認する人は少ないと思います。
スキルを起動したタイミングで、お知らせ(アップデート後の一回だけ)できれば良いなと思うのでやってみました。

概要

  1. ユーザーの最後のスキル起動日時(lastLaunch)を記録する
  2. お知らせするメッセージと時間(lastUpdate)を静的ファイルなどに書いておく
  3. lastLaunch < lastUpdate の場合は、メッセージをお知らせする。

という仕組みです。

1.に関しては、ask-utilsSetLaunchCountInterceptorを使って実現します。

コード

index.ts

import moment from 'moment';
import updateInfo from './updateInfo.json';

const s3PersistenceAdapter = new Adapter.S3PersistenceAdapter({
  bucketName: `${process.env.SERVICE_NAME}-${process.env.ENV}`,
});


export const alexa = Ask.SkillBuilders.custom()
  .addRequestHandlers(
    LaunchRequestHandler
  )
  .addRequestInterceptors(SetLaunchCountInterceptor) // 1. ユーザーの最後のスキル起動日時を記録する
  .withApiClient(new Ask.DefaultApiClient())
  .withPersistenceAdapter(s3PersistenceAdapter)
  .lambda();


const LaunchRequestHandler = {
  canHandle(handlerInput: Ask.HandlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'LaunchRequest';
  },
  async handle(handlerInput: Ask.HandlerInput) {
      // 3. メッセージをお知らせする。
      if (moment(updateInfo.lastUpdate).isAfter(moment.unix(lastLaunch))) {
        progressiveResponse(handlerInput, updateInfo.message.join('<break time="300ms"/>')); //progressiveResponse関数は省略
      }
    }
    return handlerInput.responseBuilder
      .speak('ハローワールド')
      .getResponse();

updateInfo.json
// 2. お知らせするメッセージと時間を静的ファイルなどに書いておく
{
    "lastUpdate": "2020-07-06T09:00:00",
    "message": [
        "アップデート情報のお知らせです。",
        "アップデートの内容はほげほげになります。"
    ]
}

その他

日付(updateInfo.lastUpdate)を未来にしておくと、その時刻までずっとお知らせすることが出来ます。
期間限定のキャンペーンなどにも応用できそうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0