Skip to content

Jack documentation #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 82 additions & 20 deletions READMEs/Configure-Alexa-to-Email-User.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,101 @@
# Configure Alexa to send emails

## [Back to Table of Contents](./Table-of-Contents.md)

sendSolutionToChallenegeEmail Feature
### User Story - Purpose of Component

- As a user I would like to recieve emails from Alexa with solutions to the code challenge I am working on.
- As a user I would like to recieve emails from Alexa with a list of daily job postings.

###
### Resources used in building this

[To link external services to the alexa skill you must first follow this guide to setup IAM permissions](https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html)
When you are creating your Alexa skill you can choose to self host or to have it "Alexa Hosted". In this application we selected "Alexa Hosted", which means she provisions certain resources that are managed by default. These services are:
- S3
- DynamoDB
- Lambda
- Cloudwatch

![Console](../img/alexa-hosted-resources.png)

[etting up the email params:](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses/)
When you go to the "Code" section in your Alexa developer console these skills will be listed at the top. All of these are available to you without any setup, with the caviat that you are granted a static role that has limited permissions. That is why to setup SES (or any other service), we need to do some setup. Check out the resource links below for the steps to allow Alexa to connect with your AWS account.

[API reference for sending the email.](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses/)
- [Linking other AWS resources](https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html)

[Document 2:](https://pamphl3t.medium.com/send-a-email-from-your-alexa-with-aws-ses-176a81515680)
You will also need to configure your SES to verify an email for sending.

# Component Name
- [Setting up SES](https://docs.aws.amazon.com/ses/latest/dg/Welcome.html)

### User Story - Purpose of Component
- [A basic walkthrough for sending emails](https://pamphl3t.medium.com/send-a-email-from-your-alexa-with-aws-ses-176a81515680)

### Resources used in building this:
Main Resources
Additional Resources
And you will need to enable permissions in the build tab of your developer console.

![Permissions](../img/alexa-permissions.png)

### Dependencies

### Intents Utterances
All you need is the AWS-SDK (which Alexa should have installed by default)

## Relevant Code Snippets

You need to grant alexa permissions to read the user email. We did this by putting the string in an array, so more permissions could be added if needed.

```js
const PERMISSIONS = ['alexa::profile:email:read']
```

This is how you grab a user's email from the account. Keep in mind they must enable it in the alexa app in the skill settings. [Here is an article that walks you through how to do this](https://www.c-sharpcorner.com/article/getting-an-email-address-in-an-alexa-skill2/).

```js

const { serviceClientFactory, responseBuilder } = handlerInput

try {
//* fetching the user's email from the account
const upsServiceClient = serviceClientFactory.getUpsServiceClient()
const profileEmail = await upsServiceClient.getProfileEmail()
//* if there is no profile with the associated account.
if (!profileEmail) {
const noEmailResponse = `It looks like you do not have an email set. You can set your email from the alexa companion app.`
return responseBuilder.speak(noEmailResponse).getResponse()
}
```

This is how Alexa assumes a temporary role that you set up in your IAMS following the "Linking other AWS resources" link. You will need this to utilize SES in any way.

```js
const sts = new aws.STS({ apiVersion: '2011-06-15' })

### Notable Code Block w/Code Description.
Link to .js file with comments for each section
const credentials = await sts
.assumeRole(
{
RoleArn: '<YOUR ALEXA ROLE ARN>',
RoleSessionName: 'SendEmailRoleSession'
},
(err, res) => {
if (err) {
console.log('AssumeRole FAILED: ', err)
throw new Error('Error while assuming role')
}
return res
}
)
.promise()
```

screenshot of the code:
Once you have permissions, you can use SES to send an email with the credentials you just made.

```js
const ses = new aws.SES({
apiVersion: '2010-12-01',
region: 'us-east-2',
accessKeyId: credentials.Credentials.AccessKeyId,
secretAccessKey: credentials.Credentials.SecretAccessKey,
sessionToken: credentials.Credentials.SessionToken
})
```

### Notable Bugs and Issues that occurred.
- Problem
- Solution
___

### Testing
### Known bugs/issues

### Known bugs/issues
None are known at the time of writing this. Make sure permissions are granted in your developer console.
120 changes: 109 additions & 11 deletions READMEs/Feature-Email-Code-Challenge-Solution.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,125 @@
# Email Code Challenge Solution to User
# Email Code Challenge Solution

## [Back to Table of Contents](./Table-of-Contents.md)

### User Story - Purpose of Component

### Resources used in building this:
As a user I would like Alexa to give me the solution to the code challenge I completed.

### Resources used in building this

Main Resources
Additional Resources

[MAKE SURE YOU CONFIGURE YOUR ALEXA FIRST](./Configure-Alexa-to-Email-User.md)

- [Linking other AWS resources](https://developer.amazon.com/en-US/docs/alexa/hosted-skills/alexa-hosted-skills-personal-aws.html)
- [Setting up the email params](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses/)
- [API reference for sending the email](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-send-email-ses/)

Additional Resources:

### Dependencies

- No dependencies required.

### Intents Utterances

### Notable Code Block w/Code Description.
Link to .js file with comments for each section
- See: [Get a code challenge](./Feature-Get-Code-Challange.md)

### Notable Code Block w/Code Description

Most of this is the same as the [Email Job report](./Feature-Email-Jobs-Report.md). Modify it to your needs. The source code may look confusing because it is built around the functionality of the timer feature.

```js
//* making the request to send an email with Alexa credentials
// 1. Assume the AWS resource role using STS AssumeRole Action

const sts = new aws.STS({ apiVersion: '2011-06-15' })

const credentials = await sts
.assumeRole(
{
RoleArn: 'ALEXA ROLE ARN',
RoleSessionName: 'SendEmailRoleSession'
},
(err, res) => {
if (err) {
console.log('AssumeRole FAILED: ', err)
throw new Error('Error while assuming role')
}
return res
}
)
.promise()

//* 2. Make a new SES object with the assumed role credentials

//* create a new SES instance
const ses = new aws.SES({
apiVersion: '2010-12-01',
region: 'us-east-1',
accessKeyId: credentials.Credentials.AccessKeyId,
secretAccessKey: credentials.Credentials.SecretAccessKey,
sessionToken: credentials.Credentials.SessionToken
})

//* async function to send the email and wait for a promise to be returned
/**
*
* @param {string} reciever The email address you want to recieve the data at
* @param {string} body The email body, the actual text inside the email. NOT HTML. //! Will be an object once feature is implemented.
* @param {string} subject The subject line of the email.
* @returns
*/
const sendEmail = async (reciever, body, subject) => {
let params = {
Destination: {
ToAddresses: [reciever]
},
Message: {
Body: {
Html: {
Charset: 'UTF-8',
Data: `<h1>Tech Prep!</h1>
<h3>Thank you for using our Alexa Skill!</h3>
<h4> Here is the code challenge that you attempted: </h4>

<div>
<p>${body.chosenChallenge.description}</p>
<a href=${body.chosenChallenge.solution}>You can view the solution here</a>
</div>`
}
},

Subject: { Data: subject }
},
Source: 'YOUR SES VERIFIED EMAIL HERE'
}


return await ses.sendEmail(params).promise()
}

//* send the email with the specified parameters
sendEmail(sessionAttributes.profileEmail, sessionAttributes, 'TechPrep Solution Code')

return handlerInput.responseBuilder
.getResponse();

//! if there are improper permissions. Sometimes they can be switched off if the skill is rebuilt/redeployed.
```

screenshot of the code:
### Notable Bugs and Issues that occurred

- Problem: Emails being recieved as undefined
- Solution: Make sure your data is passed into the sendEmail function correctly.

### Notable Bugs and Issues that occurred.
- Problem
- Solution
- Problem: Permissions issues
- Solution:
- 1. Make sure your ARN's are correct
- 2. Make sure your role is configured properly
- 3. Make sure your SES verified email is EXACTLY the same as it is in AWS. Even a capital letter will break it.

### Testing
### Known bugs/issues

### Known bugs/issues
No known bugs at the time of writing this. Sometimes emails are sent to spam or junk.
29 changes: 0 additions & 29 deletions READMEs/Feature-Email-Jobs-Report

This file was deleted.

Loading