Alexa does not natively support Plex commands. While you can control Plex playback on certain devices using Alexa, direct integration for managing Plex library content like creating playlists is not available.
However, it is possible to create a workaround using a custom Alexa skill and leveraging Plex’s Web API, which is the link you shared. This requires a good understanding of programming and dealing with APIs. Here’s a high-level overview of the process:
- Create an Alexa Skill: You will need to create a custom skill using the Alexa Skills Kit. Amazon provides comprehensive guides on how to do this.
- Write the Alexa Skill Logic: The skill should accept a command to create a playlist on Plex. You will need to process this command and use it to generate a request to the Plex Web API.
- Authenticate with Plex: Plex requires an authentication token to use its API. You will need to manage this token within your Alexa Skill. This could involve creating a separate login flow for your skill or storing your Plex token within the skill (though this is less secure).
- Call the Plex API: Once you have an authentication token, you can call the Plex API to create a playlist. The API requires several parameters to create a playlist, including the playlist’s title and the items to add to the playlist. You will need to determine how to handle these in your Alexa skill.
- Handle API Responses: After calling the Plex API, you will need to handle the response in your Alexa skill. This could involve confirming that the playlist was created successfully, or informing the user of any errors.
Again, this is a complex process that requires a good understanding of programming, and it might be against the Plex’s terms of service. Be sure to check the most recent documentation and terms for both Amazon Alexa and Plex to ensure you’re in compliance.
Creating a custom Alexa skill involves several steps. In general, you’ll be using the Alexa Skills Kit, which is a collection of self-service APIs, tools, documentation, and code samples that make it easier to start building Alexa skills.
As of my knowledge cutoff in September 2021, here are the steps you would need to follow to create an Alexa skill:
- Set up an Amazon Developer Account: Go to the Amazon Developer Services webpage (developer.amazon.com) and create an account if you don’t already have one. This account is free.
- Create a New Skill: Once you have an Amazon Developer account, navigate to the Alexa section of the website, then to the Alexa Skills Kit. From there, you’ll want to click on “Create Skill”.
- Choose a Skill Name and Default Language: Enter a name for your skill. This is the name that will be displayed in the Alexa Skills Store, and it’s also what users will say to trigger the skill. Choose a default language for your skill.
- Choose a Model to Add to Your Skill: Alexa provides several built-in models for skills, such as “Custom”, “Smart Home”, “Video”, and “Music”. For a Plex playlist skill, you’ll probably want to choose “Custom”.
- Choose a Method to Host Your Skill’s Backend Resources: You have a choice of provisioning your own or letting Alexa host it for you. If you’re comfortable with AWS Lambda, you might choose to provision your own. If you’re not sure, let Alexa host it for you.
- Choose a Template: Amazon provides several templates that can help you get started. You can choose one of these or start from scratch. For a Plex playlist skill, you’ll probably want to start from scratch.
- Skill Builder Dashboard: Once you’ve made these decisions, you’ll be taken to the Skill Builder Dashboard. This is where you’ll build your skill. You’ll define an interaction model (including intents, slots, and dialog models), configure the skill’s interface, and test the skill.
- Build the Interaction Model: This is where you define what users can say to interact with your skill, and how Alexa should respond. You’ll define intents (representing actions that fulfill a user’s spoken request), slots (variables that represent potential user inputs), and sample utterances (specific phrases that people might say when invoking your intents).
- Code Your Skill: After setting up the interaction model, you need to code the logic of your skill. This is usually done in AWS Lambda, a service offered by Amazon Web Services. Your code will handle different intents and formulate responses that Alexa will say back to the user.
- Test Your Skill: Once your skill’s logic is written, you’ll need to test it. You can do this through the Skill Builder Dashboard, or by using an Alexa-enabled device that’s associated with your Amazon Developer account.
- Prepare for Publishing: Once your skill is working as expected, you’ll need to complete the Publishing Information and Privacy and Compliance sections of the Skill Builder Dashboard.
- Submit for Certification: Once everything is complete and working as expected, you can submit your skill for certification. Amazon will review your skill, and if it meets their quality and policy criteria, it will be published in the Alexa Skills Store.
Remember, this is a high-level overview and every step involves its own complexities. Also, keep in mind that as the tech world moves fast, there might have been changes or updates to the process after my last training data in September 2021.
Setting up an Amazon Developer Account
Setting up an Amazon Developer Account is a straightforward process. Here are the steps you need to follow:
- Visit the Amazon Developer Website: Go to developer.amazon.com. You’ll see a “Sign In” button in the top right corner of the webpage.
- Sign In or Create an Account: Click on the “Sign In” button. This will take you to a login page where you can either sign in with an existing Amazon account or create a new one. If you already have an Amazon account (for example, for Amazon.com or AWS), you can use that to sign in. If you don’t have an Amazon account or want to create a separate one for development, click on “Create your Amazon account” and follow the instructions.
- Enter Your Account Information: If you’re creating a new account, you’ll be asked to provide some basic information, such as your name, email address, and a password.
- Confirm Your Email Address: After you’ve entered your account information, Amazon will send a confirmation email to the address you provided. Click the link in that email to confirm your email address and complete the account creation process.
- Complete Your Developer Profile: Once you’ve confirmed your email address, you’ll be asked to complete your developer profile. This includes information like your developer name (which can be your actual name or a company name), your website (if you have one), a phone number, and your address.
- Agree to the Terms and Conditions: Review Amazon’s App Distribution and Services Agreement. If you agree with the terms, check the appropriate box to indicate your agreement.
- Complete the Registration: Click the “Save and Continue” button to complete your registration.
Congratulations! You now have an Amazon Developer account. This will allow you to create and manage Alexa Skills, use other Amazon services such as AWS, and more.
Remember, to keep your login credentials safe and secure, as your developer account can potentially have access to sensitive data and services.
How to create an Alexa skill
Creating a custom Alexa skill involves several steps. In general, you’ll be using the Alexa Skills Kit, which is a collection of self-service APIs, tools, documentation, and code samples that make it easier to start building Alexa skills.
As of my knowledge cutoff in September 2021, here are the steps you would need to follow to create an Alexa skill:
- Set up an Amazon Developer Account: Go to the Amazon Developer Services webpage (developer.amazon.com) and create an account if you don’t already have one. This account is free.
- Create a New Skill: Once you have an Amazon Developer account, navigate to the Alexa section of the website, then to the Alexa Skills Kit. From there, you’ll want to click on “Create Skill”.
- Choose a Skill Name and Default Language: Enter a name for your skill. This is the name that will be displayed in the Alexa Skills Store, and it’s also what users will say to trigger the skill. Choose a default language for your skill.
- Choose a Model to Add to Your Skill: Alexa provides several built-in models for skills, such as “Custom”, “Smart Home”, “Video”, and “Music”. For a Plex playlist skill, you’ll probably want to choose “Custom”.
- Choose a Method to Host Your Skill’s Backend Resources: You have a choice of provisioning your own or letting Alexa host it for you. If you’re comfortable with AWS Lambda, you might choose to provision your own. If you’re not sure, let Alexa host it for you.
- Choose a Template: Amazon provides several templates that can help you get started. You can choose one of these or start from scratch. For a Plex playlist skill, you’ll probably want to start from scratch.
- Skill Builder Dashboard: Once you’ve made these decisions, you’ll be taken to the Skill Builder Dashboard. This is where you’ll build your skill. You’ll define an interaction model (including intents, slots, and dialog models), configure the skill’s interface, and test the skill.
- Build the Interaction Model: This is where you define what users can say to interact with your skill, and how Alexa should respond. You’ll define intents (representing actions that fulfill a user’s spoken request), slots (variables that represent potential user inputs), and sample utterances (specific phrases that people might say when invoking your intents).
- Code Your Skill: After setting up the interaction model, you need to code the logic of your skill. This is usually done in AWS Lambda, a service offered by Amazon Web Services. Your code will handle different intents and formulate responses that Alexa will say back to the user.
- Test Your Skill: Once your skill’s logic is written, you’ll need to test it. You can do this through the Skill Builder Dashboard, or by using an Alexa-enabled device that’s associated with your Amazon Developer account.
- Prepare for Publishing: Once your skill is working as expected, you’ll need to complete the Publishing Information and Privacy and Compliance sections of the Skill Builder Dashboard.
- Submit for Certification: Once everything is complete and working as expected, you can submit your skill for certification. Amazon will review your skill, and if it meets their quality and policy criteria, it will be published in the Alexa Skills Store.
Remember, this is a high-level overview and every step involves its own complexities. Also, keep in mind that as the tech world moves fast, there might have been changes or updates to the process after my last training data in September 2021.
Write the Alexa Skill Logic
Writing the logic for an Alexa skill involves handling the different intents your skill supports. This typically involves writing a handler for each intent and then defining how Alexa should respond to it. The skill logic is usually written as a cloud-based service and hosted on AWS Lambda, although you can host it on any HTTPS-enabled endpoint.
Here’s a step-by-step guide:
- Create an AWS Lambda Function: Go to the AWS Management Console, select “Lambda” from the “Services” dropdown, and then click on “Create function”. Select “Author from scratch”, provide a function name, select a runtime (Node.js, Python, and Java are supported), and then create the function. You will receive an ARN (Amazon Resource Name) for your function, which you’ll need later.
- Create an Execution Role for the Lambda Function: In the AWS console, go to IAM (Identity and Access Management), then “Roles”, and then “Create Role”. Select “Lambda” as the service that will use this role, and then click “Next: Permissions”. Attach the “AWSLambdaBasicExecutionRole” policy and then create the role.
- Assign the Role to the Lambda Function: Go back to your Lambda function and assign the role you just created in the “Execution Role” section.
- Write Your Skill’s Logic: This is where you actually write the code that handles your skill’s functionality. You’ll need a handler for each intent that your skill supports. For example, if your skill supports an intent to create a Plex playlist, you might have a handler like this (in Node.js):
const CreatePlaylistIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'CreatePlaylistIntent';
},
handle(handlerInput) {
// Your logic to create a Plex playlist goes here
// Call the Plex API and handle the response
const speakOutput = 'Your Plex playlist was created successfully.'; // Customize this based on the actual result
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
This code defines a handler for an intent named “CreatePlaylistIntent”. When this intent is triggered, the handler calls the Plex API to create a playlist, and then generates a response that Alexa will speak to the user.
- Handle LaunchRequest and Other Built-In Intents: In addition to your custom intents, you should handle the
LaunchRequest
(which is triggered when the user opens your skill without providing a specific intent), as well as other built-in intents likeAMAZON.HelpIntent
,AMAZON.CancelIntent
, andAMAZON.StopIntent
. - Add Your Intent Handlers to the Lambda Function: Your Lambda function needs to know about your intent handlers. You do this by registering the handlers with the
addRequestHandlers
function. Here’s an example:
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
CreatePlaylistIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler
)
.lambda();
- Test Your Skill’s Logic: After you’ve written your skill’s logic and added your handlers to the Lambda function, you should test your skill to make sure it works correctly. You can do this in the Alexa Developer Console’s “Test” tab, or by speaking to an Alexa-enabled device that’s associated with your developer account.
Please note that this is a very high-level overview of writing an Alexa skill’s logic and the specifics might vary based on the programming language you use and the specifics of
Get a Plex Token
Authentication is a crucial step to access the Plex Media Server API. Plex uses a token-based authentication system. Therefore, you’ll need a valid token to authenticate your requests.
Here’s a general process to authenticate with Plex:
- Get a Plex Token: The first step is to acquire an authentication token. One way to obtain a token is by signing in to an account at
https://plex.tv/users/sign_in.json
with a POST request, sending along your Plex username and password. You can use a tool likecurl
for this:curl -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" -H "X-Plex-Client-Identifier: YOUR_UNIQUE_IDENTIFIER" -H "X-Plex-Product: YOUR_APP_NAME" -H "X-Plex-Version: YOUR_APP_VERSION" --data-urlencode "user[login]=YOUR_PLEX_USERNAME" --data-urlencode "user[password]=YOUR_PLEX_PASSWORD" https://plex.tv/users/sign_in.json
You’ll need to replaceYOUR_UNIQUE_IDENTIFIER
,YOUR_APP_NAME
,YOUR_APP_VERSION
,YOUR_PLEX_USERNAME
, andYOUR_PLEX_PASSWORD
with your actual values. If successful, this will return a JSON response containing an authentication token. This token will be under the keyuser.authToken
. Important: Be very careful when handling your Plex username and password, and never expose them in an insecure manner. Also, the token you receive should be treated just like a password and stored securely. - Use the Plex Token: Once you have your Plex token, you must include it in every request to the Plex API by adding it as a parameter to the URL (e.g.,
http://your.plex.server:32400/library/sections?X-Plex-Token=YOUR_PLEX_TOKEN
). - Refresh the Plex Token: Plex tokens do not expire by themselves. However, a user can choose to manually invalidate a token by signing out of their Plex account. Therefore, your Alexa skill should be prepared to handle a situation where the token becomes invalid. In such cases, you would need to acquire a new token by repeating the sign-in process.
Again, this is a high-level description and actual implementation might differ based on the specifics of your application. Always refer to the most up-to-date Plex documentation when working with their API. Also, note that storing sensitive data like Plex tokens within an Alexa skill could have privacy and security implications, so always ensure to comply with all relevant guidelines and best practices.
Call the Plex API
Once you’ve authenticated with Plex and obtained an authentication token, you can use this token to make requests to the Plex API. The specific request you make will depend on what you’re trying to achieve.
Given your earlier question, I’m assuming you want to create a playlist. As of my last update in 2021, creating a playlist using the Plex API involves the following steps:
- Identify the Items to Add to the Playlist: Before you can create a playlist, you need to know the items you want to add to it. Items in Plex are identified by a key, which is a unique identifier used by Plex. You’ll need to find the keys for the items you want to add to your playlist. This might involve making a separate API request to retrieve the keys.
- Create the Playlist: According to the Plex API documentation, you create a playlist by sending a POST request to
/playlists
. The request must include several parameters:uri
: A string that represents the items to add to the playlist. It should be in the formatlibrary://<UUID>/item/%2Flibrary%2Fmetadata%2F<KEY>
, where<UUID>
is the unique identifier of the library the items belong to, and<KEY>
is the key of the item.type
: The type of the playlist. This should bevideo
for a video playlist, oraudio
for an audio playlist.title
: The title of the playlist.smart
: A boolean value indicating whether the playlist is a smart playlist. You can probably ignore this for a basic playlist.
The specific code to call the Plex API will depend on the programming language you’re using and the specifics of your application. Here’s an example of how you might do this in Python using the requests
library:
import requests
plex_token = "YOUR_PLEX_TOKEN" # Replace with your actual Plex token
plex_server_url = "http://your.plex.server:32400" # Replace with your actual Plex server URL
playlist_title = "My Playlist" # Replace with your actual playlist title
playlist_type = "video" # or "audio"
playlist_uri = "library://<UUID>/item/%2Flibrary%2Fmetadata%2F<KEY>" # Replace <UUID> and <KEY>
url = f"{plex_server_url}/playlists"
params = {
"uri": playlist_uri,
"type": playlist_type,
"title": playlist_title,
"X-Plex-Token": plex_token
}
response = requests.post(url, params=params)
# Check the response
if response.status_code == 200:
print("Playlist created successfully!")
else:
print("Failed to create playlist:", response.content)
This code sends a POST request to the /playlists
endpoint of your Plex server, passing the necessary parameters to create a playlist. If the request is successful, it prints a success message; otherwise, it prints an error message.
Remember, this is a high-level guide and actual implementation might differ based on the specifics of your application. Always refer to the most up-to-date Plex documentation when working with their API. Also, note that handling sensitive data like Plex tokens within an Alexa skill could have privacy and security implications, so always ensure to comply with all relevant guidelines and best practices.