关于Alexa Skill可配置化及配置表单创建的技术问询
Alexa Skill可配置化及配置表单创建的技术问询
Hey there! Great question—setting up a config form for your Alexa Skill so users can customize the API endpoint based on where they’ve hosted it is totally achievable, and there are two straightforward approaches you can take:
1. Use Alexa’s Built-in Custom Settings (Simplest Option)
Alexa has a built-in way to add custom settings directly to the Alexa app for your skill. Here’s how:
- Head to your Alexa Developer Console, open your skill, and go to the Build tab. Navigate to Interfaces > Settings and enable custom settings.
- You can define input fields (like a text box for the API URL) here—these will show up under the "Settings" section of your skill’s page in the user’s Alexa app.
- Once users fill in their API endpoint, you can pull that value right in your skill code. For example, in Node.js:
const settingsClient = handlerInput.serviceClientFactory.getSettingsServiceClient(); const userApiEndpoint = await settingsClient.getUserSetting('api_endpoint'); // Use this endpoint for your API calls
2. Build a Custom Web Config Page (For More Flexibility)
If you need a more robust config experience (like adding validation, dropdowns, or additional fields), you can create your own simple web page where users input their API details:
- Set up a basic web interface that lets users enter their API URL and save it to a database tied to their account.
- Use Account Linking in your Alexa Skill to connect the user’s Alexa account to your web service account. This gives your skill access to a token you can use to fetch the user’s saved config.
- Here’s a quick snippet of how you might fetch the config in your skill code (Node.js example):
async function fetchUserApiConfig(handlerInput) { const userToken = handlerInput.requestEnvelope.context.System.user.accessToken; const response = await fetch('https://your-custom-service.com/user/config', { headers: { Authorization: `Bearer ${userToken}` } }); const userConfig = await response.json(); return userConfig.apiEndpoint; }
Quick Tips
- Always add validation for the API URL—either in your config form or skill code—to make sure it’s a valid HTTP/HTTPS address. This prevents errors when your skill tries to call the API later.
- If you want to reduce repeated calls to fetch the config, you can save the API endpoint to your skill’s Persistent Attributes after the first fetch. That way, you can pull it directly from storage next time.
备注:内容来源于stack exchange,提问作者Vinicius Andrade
相关产品推荐
相关产品推荐

