0

AWS Lambda、Node.js、Alexa Skills Kitを使用してAlexaスキルを開発しています。 -nodejs-fact project & &が正常にデプロイされました。サンプルファクトプロジェクトがテストされました。次に、いくつかのFacebookフィードの投稿を読むためにそのコードを変更しようとしています。投稿を読むことができるノードアプリケーションを開発しようとしました。&、あなたのreference.IのコードFBモジュール使用の下に - https://www.npmjs.com/package/fbAWS Lambda、Node.js、Alexaスキルキットを使用してFacebook投稿を読むことができるAlexaスキル

const FB = require('fb'); 
FB.setAccessToken('abc'); 
const query='cnninternational/posts'; 

FB.api(query, function (res) { 
    if(!res || res.error) { 
    console.log(!res ? 'error occurred' : res.error); 
    return; 
    } 
    console.log(res); 
}); 

次へ]を、私はタラの上に統合しようとしましたこれらのコードを使用してFacebookの投稿を読むことはできませんでした。下のパネルでそのコードブロックを見つけてください。また、雲のログも確認しました。「GetNewsIntent」が表示されていますが、ログに "fb-init"、 "fb-error"または "fb-exit"のエントリが表示されませんでした。確かにログにもエラーはありません。誰かがその問題を解決することができれば幸いです。

'use strict'; 
const Alexa = require('alexa-sdk'); 
const FB = require('fb'); 
const APP_ID = 'abc'; 

const SKILL_NAME = 'test'; 
const GET_FACT_MESSAGE = "Here's your news: "; 
const STOP_MESSAGE = 'Goodbye!'; 


exports.handler = function(event, context, callback) { 
    var alexa = Alexa.handler(event, context); 
    alexa.appId = APP_ID; 
    alexa.registerHandlers(handlers); 
    alexa.execute(); 
}; 

const handlers = { 
    'LaunchRequest': function() { 
     this.emit('GetNewsIntent'); 
    }, 
    'GetNewsIntent': function() { 

     console.log('GetNewsIntent'); 
     const speechOutput = GET_FACT_MESSAGE; 
     const query='cnninternational/posts'; 
     FB.setAccessToken('abc'); 
     FB.api(query, function (res) { 
      console.log('fb-init'); 
      if(!res || res.error) { 
      console.log(!res ? 'error occurred' : res.error); 
      console.log('fb-error'); 
      return; 
      } 
      console.log(res); 
      speechOutput = speechOutput + res; 
      console.log('fb-exit'); 
     }); 

     this.response.cardRenderer(SKILL_NAME, speechOutput); 
     this.response.speak(speechOutput); 
     this.emit(':responseReady'); 
    }, 
    'AMAZON.StopIntent': function() { 
     this.response.speak(STOP_MESSAGE); 
     this.emit(':responseReady'); 
    }, 
}; 

答えて

0

this.response.cardRendererを削除しました。this.response.speak &はコードビットを変更しました。今すぐ動作します。下記のコードスニペットを参照して、BBC Facebookページの記事を読むことができます。

var accessToken = ''; 
 

 
exports.handler = function(event, context, callback) { 
 
    var alexa = Alexa.handler(event, context); 
 
    alexa.appId = APP_ID; 
 
    alexa.registerHandlers(handlers); 
 
    alexa.execute(); 
 
}; 
 

 
const handlers = { 
 
    'NewSession': function() { 
 
     var welcomeMessage = "Welcome to Athena"; 
 
     welcomeMessage = welcomeMessage +"<break time=\"1s\"/>"+ "<audio src='https://s3.amazonaws.com/my-ssml-samples/Flourish.mp3' />"+"<break time=\"1s\"/>"; 
 
     welcomeMessage += HELP_MESSAGE; 
 
     accessToken = this.event.session.user.accessToken; 
 
     if (accessToken) { 
 
      FB.setAccessToken(accessToken); 
 
      this.emit(':ask', welcomeMessage, HELP_REPROMPT); 
 
     } 
 
     else { 
 
      // If we don't have an access token, we close down the skill. 
 
      this.emit(':tellWithLinkAccountCard', "This skill requires you to link a Facebook account. Seems like you are not linked to a Facebook Account. Please link a valid Facebook account and try again."); 
 
     } 
 
    }, 
 
    'LaunchRequest': function() { 
 
     this.emit('NewSession'); 
 
    }, 
 
    'ReadBbcNewsFacebookPostsIntent': function() {   
 
     var alexa = this; 
 
     FB.api("bbcnews/posts", function (response) { 
 
      if (response && !response.error) { 
 
       if (response.data) { 
 
        var output = "Here are recent posts" + "<break time=\"1s\"/>"; 
 
        var max = 5; 
 
        for (var i = 0; i < response.data.length; i++) { 
 
         if (i < max) { 
 
          output += "<break time=\"1s\"/>" + "Post " + 
 
          (i + 1) + 
 
          response.data[i].message.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') 
 
           + ". "; 
 
         } 
 
        } 
 
        alexa.emit(':ask', output+ ", What would you like to do next?",HELP_MESSAGE); 
 
       } else { 
 
        // REPORT PROBLEM WITH PARSING DATA 
 
       } 
 
      } else { 
 
       // Handle errors here. 
 
       console.log(response.error); 
 
       this.emit(':tell', EMPTY_ACCESS_TOKEN_MESSAGE, TRY_AGAIN_MESSAGE); 
 
      } 
 
     }); 
 
    } 
 
};

0

account linkingを実装しましたか?パラメータはsetAccessToken()にはevent.session.user.accessTokenを使用する必要があります。

+0

あなたの応答Ben.Yesのためのおかげで、私did.Iはthis.event.session.user.accessToken.Accountリンクの値が成功しているハードコード。 –

関連する問題