Last active
May 18, 2022 18:10
-
-
Save mniak/bf7319fc3d24d2a515aac9b965f15d4b to your computer and use it in GitHub Desktop.
Revisions
-
mniak revised this gist
May 18, 2022 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,9 @@ Skill para Bater Ponto no sistema ADP Expert Backend -------- Sugiro hospedar no Vercel. https://vercel.com/docs/runtimes#official-runtimes/go Configuração da Skill --------------------- -
mniak revised this gist
May 18, 2022 . 2 changed files with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ Skill para Bater Ponto no sistema ADP Expert ============================================ Backend -------- Sugiro hospedar no [Vercel](vercel.app). Basta criar um repositório, rodar `go mod init <packagename> e copiar o arquivo `index.go` na pasta `api/ponto`. Configuração da Skill --------------------- Acesse o [painel de desenvolvimento da Amazon Alexa](https://developer.amazon.com/alexa/console/ask), e crie uma skill. Em **Assets > Endpoints**, cadastre o seu backend, (algo como `http://meubackend.vercel.app/api/ponto`) e selecione a opção de certificado com _wildcard_. Em **Intents > JSON Editor**, cole o conteúdo do arquivo `skill.json`. É mais ou menos isso. Ainda precisa salver, buildar, publicar, etc. Mas não vou explicar tudo porque nem lembro. Boa sorte. File renamed without changes. -
mniak revised this gist
May 18, 2022 . 1 changed file with 62 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ { "interactionModel": { "languageModel": { "invocationName": "controle de ponto", "intents": [ { "name": "AMAZON.CancelIntent", "samples": [] }, { "name": "AMAZON.HelpIntent", "samples": [] }, { "name": "AMAZON.StopIntent", "samples": [] }, { "name": "AMAZON.NavigateHomeIntent", "samples": [] }, { "name": "Marcar", "slots": [], "samples": [ "inicia", "sai", "entra", "sair", "marca saída", "entrar", "marca entrada", "marca", "marcar", "marca o ponto", "bate o ponto", "marcar ponto", "marcar meu ponto", "marcar o ponto", "bater ponto", "bater meu ponto", "bater o ponto" ] }, { "name": "Consultar", "slots": [], "samples": [ "Relatório", "Última marcação", "Qual o horário da última marcação", "Quando foi a última marcação", "Verificar", "Consulte", "Consultar" ] } ], "types": [] } } } -
mniak created this gist
May 18, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,101 @@ package ponto import ( "context" "fmt" "log" "net/http" "strings" "github.com/go-resty/resty/v2" "github.com/mniak/adpexpert" "github.com/mniak/alexa" ) const ( skillName = "Controle de Ponto" appID = "amzn1.ask.skill.<SKILL_ID>" ) const ( username = "jair.lula" password = "abcdefghijklmno" ) func Handler(w http.ResponseWriter, r *http.Request) { handler := alexa.NewSkillBuilder(appID). SetIgnoreApplicationID(true). SetIgnoreTimestamp(true). WithOnSessionStarted(SessionStart). WithOnIntent(Intent). BuildHTTPHandler() handler(w, r) } func SessionStart(ctx context.Context, req *alexa.Request, session *alexa.Session, context *alexa.Context, resp *alexa.Response) error { message := fmt.Sprintf("%s iniciado", skillName) resp.SetOutputText(message) resp.SetSimpleCard(skillName, message) resp.ShouldSessionEnd = false return nil } func Intent(ctx context.Context, req *alexa.Request, session *alexa.Session, context *alexa.Context, resp *alexa.Response) error { var message string switch req.Intent.Name { case "Marcar": message, _ = IntentMarcar() case "Consultar": message, _ = IntentConsultar() default: message = "Não conheço esta opção" } resp.SetOutputText(message) resp.SetSimpleCard(skillName, message) resp.ShouldSessionEnd = true return nil } func IntentMarcar() (string, bool) { adpclient := adpexpert.Client{ Debug: true, } err := adpclient.Login(username, password) if err != nil { return fmt.Sprintf("O login falhou: %s", err), false } err = adpclient.PunchIn() if err != nil { return fmt.Sprintf("Deu erro: %s", err), false } return "Ponto marcado!", true } func IntentConsultar() (string, bool) { adpclient := adpexpert.Client{ Debug: true, } err := adpclient.Login(username, password) if err != nil { return fmt.Sprintf("O login falhou: %s", err), false } punches, err := adpclient.GetLastPunches() if err != nil { return fmt.Sprintf("Não consegui baixar as marcações: %s", err), false } if len(punches.LastPunches) == 0 { return "Você não tem marcações recentes", true } last := punches.LastPunches[0] return fmt.Sprintf("A última marcação foi às %d:%02d", last.PunchDateTime.Hour(), last.PunchDateTime.Minute()), true }