Salesforce Alexa Integration
Will it not be interesting if Alexa can get to details of new cases from Salesforce??
Yes!! You heard it right. In this article, I will help you with the steps to integrate Salesforce with Amazon Alexa.
The scope of this document will be restricted to showcase one of the capability and not solve any business use case.
What is Alexa? Amazon Alexa, also known simply as Alexa, is a virtual assistant AI technology developed by Amazon, first used in the Amazon Echo smart speakers is capable of voice interaction, music playback, etc. Users can extend the Alexa capabilities by installing "skills" (additional functionality developed by third-party vendors, in other settings more commonly called apps such as weather programs and audio features).
Design - We will create a Java application, which will connect to Salesforce and Amazon Alexa through their respective APIs. We will use AWS Lambda to run our code. AWS Lambda lets you run code without provisioning or managing servers. We will create a custom Alexa skill (using Alexa developer console), which can be enabled in Alexa supported devices and takes user inputs/commands. The Alexa skill will handle the user request and direct it towards the AWS Lambda function to get you the response.
- Login to Salesforce
- Go to Set up and type API in a quick search
- Click on Enterprise WSDL to download the WSDL file. You would need to generate required jar files using a Web service connector from Salesforce. More information in Web Service Connector here.
For this use case, We will create below 4 java classes.
- LaunchRequestHandler.java - To handle initial user request
- CaseRequestHandler.java - To request salesforce case information
- QuerySalesforce – Logic to retrieve Case information from Salesforce
- SalesforceAlexaSkillStreamHandle – Include the above two handlers
On the left accordion, click invocation to change the skill invocation name. I have kept it as a ‘geeksoft salesforce’ as in the screenshot below. Alexa users say a skill's invocation name to begin an interaction with a particular custom skill. For example, for the invocation name is "geeksoft salesforce", users can say:
User: “Alexa, ask geeksoft salesforce how many new cases are assigned to me”
Remember to hit the ‘save model’ button at the top to save your changes. This saves your data but does not build the model. We will be looking into the ‘Build Model’ in some time.
You will need to create an Intent that can respond to Salesforce queries. If you have already worked on Einstein BOT on Salesforce service cloud, Intents and building a model should not be a surprise to you. More about Salesforce bot Intents here.
Click on Interaction on the left accordion and then click on Intents. Click ‘Add Intents’ as in the below screenshot to create one. An intent represents an action that fulfills a user's spoken request.
For Salesforce Interaction, I have created Case intent as in the below screenshot. You can add some good numbers of utterances. I have included only 5 and should be good to start with. The utterances are a set of likely spoken phrases mapped to the intents.
Next, you need to retrieve a unique Id for your skill. Select Endpoint from left accordion and then select AWS Lambda ARN. Note down your skill ID which you need at a later point while linking Alexa skill to the AWS Lambda function. The Endpoint will receive POST requests when a user interacts with your Alexa Skill.
Once you have saved the endpoint, click on Interaction Model on the left accordion, and then hit the build model button. Alexa will run background jobs to get your AI Interaction model ready. This should look similar to the Salesforce Einstein bot Build model. Your changes will be validated and saved while building an Interaction model.
AWS Lambda function - Once you are done with the above step, you need to login to the AWS account to create aa IAM role and Lambda function. The IAM role is AWS identity with permission policies that determine what the identity can and cannot do in AWS.Login here using your credentials, and then click on IAM under services as in the screenshot below.
Click on roles to create a new role.