Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Микро-библиотека для платформы Яндекс.Диалоги

License

Notifications You must be signed in to change notification settings

savely-krasovsky/go-alice-dialogs-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-alice-dialogs-api

GoDoc

Микро-библиотека для упрощения работы с новой платформой Яндекс.Диалоги. Проще всего показать всё сразу на примере:

package main

import (
	"go-alice-dialogs-api"
	"net/http"
	"strings"
)

func HandleDialog(req aliceapi.Request) aliceapi.Response {
	// Стандартный ответ
	text := "Что?"
	button := aliceapi.Button{
		Title: "Кнопка!",
		URL:   "https://ru.wikipedia.org/wiki/Hello%2C_world!",
	}

	// Обрабатываем "Привет!" от пользователя
	if strings.Contains(strings.ToLower(req.Command), "привет") {
		text = "Тебе тоже!"
	}

	if req.Command == button.Title {
		text = "Похоже ты затестил кнопку!"
	}

	// Отправляем готовый ответ Алисе
	return aliceapi.Response{
		Text:    text,
		Buttons: []aliceapi.Button{button},
	}
}

func main() {
	// Регистрируем главный обработчик
	aliceapi.Handle("/", HandleDialog)

	// Поднимаем собственный вебсервер и слушаем вебхуки
	http.ListenAndServeTLS("0.0.0.0:7443", "cert.pem", "key.pem", nil)
}

About

Микро-библиотека для платформы Яндекс.Диалоги

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages