Alexa技能-检索客户邮件地址node.js

时间:2018-12-08 15:18:10

标签: alexa

我不明白使用该方法在Alexa中检索客户邮件的方法

医生说要发出带有令牌的请求。

https://developer.amazon.com/fr/docs/custom-skills/request-customer-contact-information-for-use-in-your-skill.html

然后我完成了:

function AlexaRequest(accessToken){
  Host: api.amazonalexa.com
  Accept: application/json
  Authorization: Bearer +accessToken+
  GET https://api.amazonalexa.com/v2/accounts/~current/settings/Profile.email
}

2个问题 1-为什么会出现“解析错误”:意外的令牌https? 2-如何获得Alexa的回复?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用 UpsServiceClient 方法来获取用户的个人信息。

按照以下步骤操作或观看详细的教程HERE

步骤1:在意图处理器中编写此代码

const GreetMeIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GreetMeIntent';
  },
  async handle(handlerInput) {
    const { requestEnvelope, serviceClientFactory, responseBuilder } = handlerInput;
    const token = requestEnvelope.context.System.user.permissions &&
      requestEnvelope.context.System.user.permissions.consentToken;
      
    if (!token) {
      return handlerInput.responseBuilder
        .speak('Please Provide Permissions!')
        .withAskForPermissionsConsentCard(['alexa::profile:email:read'])
        .getResponse();
    }

    let {deviceId} = requestEnvelope.context.System.device;
    const upsServiceClient = serviceClientFactory.getUpsServiceClient();
    const email = await upsServiceClient.getProfileEmail();
    
    let speechText = `Hello! Your email is ${email}`;

    return handlerInput.responseBuilder
    .speak(speechText)
    .withSimpleCard('Hello World', speechText)
    .getResponse();
    
  },
}

步骤2:在导出中添加 withApiClient

exports.handler = skillBuilder
  .addRequestHandlers(
    GreetMeIntentHandler
  )
  .addErrorHandlers(ErrorHandler)
  .withApiClient(new Alexa.DefaultApiClient())
  .lambda();