Documentation ¶
Index ¶
- Constants
- Variables
- type TodoRepository
- type TodoService
- func (service *TodoService) Add(_ context.Context, request golexa.Request) (golexa.Response, error)
- func (service *TodoService) List(_ context.Context, request golexa.Request) (golexa.Response, error)
- func (service *TodoService) Remove(_ context.Context, request golexa.Request) (golexa.Response, error)
Constants ¶
const IntentAddTodoItem = "AddTodoItem"
IntentAddTodoItem is the name of the intent where we add new items to the user's list
const IntentListTodoItems = "ListTodoItems"
IntentListTodoItems is the name of the intent where we have Alexa rattle off all of a user's items
const IntentRemoveTodoItem = "RemoveTodoItem"
IntentRemoveTodoItem is the name of the intent where we remove items from the user's list
const SlotItemName = "item_name"
SlotItemName is the name of the slot where users specify items to add/remove.
Variables ¶
var ErrItemNotFound = errors.New("item not found")
ErrItemNotFound indicates a failure due to the desired item not being in the list. Duh....
Functions ¶
This section is empty.
Types ¶
type TodoRepository ¶
type TodoRepository struct {
// contains filtered or unexported fields
}
TodoRepository provides our fake database interactions.
func NewTodoRepository ¶
func NewTodoRepository() TodoRepository
NewTodoRepository creates a new facade for interacting with our fake database. This is just an in memory map of "userID->list" which is horrible for a skill since your Lambda's storage is ephemeral. The point of this sample is not to show you how to access databases from within lambda code - it's to show you how to properly structure your code for a clean skill implementation.
func (*TodoRepository) AddItem ¶
func (r *TodoRepository) AddItem(userID, itemName string)
AddItem adds the specified item to the end of the user's list.
func (*TodoRepository) GetItems ¶
func (r *TodoRepository) GetItems(userID string) []string
GetItems fetches the list of items for the given user.
func (*TodoRepository) RemoveItem ¶
func (r *TodoRepository) RemoveItem(userID, itemName string) error
RemoveItem provides the "hand-waving" for our business logic to remove an item from this user's list in the "database".
type TodoService ¶
type TodoService struct {
// contains filtered or unexported fields
}
TodoService wrangles all of of the dependencies for our list management business logic as well as our handlers and response templates for the various interactions we support.
func NewTodoService ¶
func NewTodoService(repository TodoRepository) TodoService
NewTodoService creates a controller/service that handles all of the intents related to managing your items list.
func (*TodoService) Add ¶
Add appends the item that the user uttered to their personal to-do list. It responds to an utterance such as "Add laundry to my to-do list" where "laundry" is the value for the {item_name} slot. Additionally, this supports an interaction such as "Update my list" where there is no item slot data. In that case, we'll have Alexa ask the user to speak the item name and try this intent/action again.
func (*TodoService) List ¶
func (service *TodoService) List(_ context.Context, request golexa.Request) (golexa.Response, error)
List simply has Alexa rattle off ALL of the items on your list. This is just a sample skill, so this would be a terrible experience if the the list were any longer than 3 or 4 items.
func (*TodoService) Remove ¶
func (service *TodoService) Remove(_ context.Context, request golexa.Request) (golexa.Response, error)
Remove obviously removes an item from the user's list who made the utterance. Just like Add(), this will have Alexa ask the user to specify which item they want to remove.