- 全カテゴリー名のリストを取得する。
- カテゴリー別の投稿リストを取得する。
- 投稿に設定したカテゴリー名を取得する
wordpress rest api
http://tztechno.site/blog/wp-json/wp/v2/posts
wordpressブログの rest api にアクセスすることで、記事の閲覧が可能である。記事番号を付加することにより特定の記事を抽出出来る。
例えば、
http://tztechno.site/blog/archives/696
の記事内容は、postmanのGETコマンドを用いて以下のURLで抽出できる。
http://tztechno.site/blog/wp-json/wp/v2/posts/696
Alexa-hosted Hello World スキルにカウンターをつける
Alexa-hosted Hello World スキルにセッション永続生を利用したカウンターをつける。
package.jsonファイル
package.jsonファイルのdependenciesセクションに、npm依存関係を追加。
"ask-sdk-s3-persistence-adapter": "^2.0.0"
index.jsファイル
index.jsファイルに以下を追加します。
// 1. ask persistence adapterの読み込み
const persistenceAdapter = require('ask-sdk-s3-persistence-adapter');
// 2. persistence adapterをスキルビルダーに追加
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
...
SesssionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.withPersistenceAdapter(
new persistenceAdapter.S3PersistenceAdapter({bucketName:process.env.S3_PERSISTENCE_BUCKET})
);
.lambda();
// 3. アトリビュートを保存するためのサンプルハンドラー
async handle(handlerInput){
const attributesManager = handlerInput.attributesManager;
let s3Attributes = {"counter":10};
attributesManager.setPersistentAttributes(s3Attributes);
await attributesManager.savePersistentAttributes();
let speechOutput = こんにちは、ハローワールド! 保存したカウンターは${s3Attributes.counter}です
;
return handlerInput.responseBuilder
.speak(speechOutput)
.getResponse();
},
// 4. アトリビュートを読み込むためのサンプルハンドラー
async handle(handlerInput){
const attributesManager = handlerInput.attributesManager;
const s3Attributes = await attributesManager.getPersistentAttributes() || {};
console.log('s3Attributes is: ', s3Attributes);
const counter = s3Attributes.hasOwnProperty('counter')? s3Attributes.counter : 0;
let speechOutput = こんにちは、ハローワールド! カウンターは${counter}です
;
return handlerInput.responseBuilder
.speak(speechOutput)
.getResponse();
},
HelloWorldIntentを起動した回数をカウントを示すために、3,4はHelloWorldIntentのhandle(handlerInput)の中に置く必要がある?