You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/l11r/go-alice-dialogs-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/l11r/go-alice-dialogs-api

v0.0.0-20180313234658-a0de179049dc
Source
Go
Version published
Created
Source

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)
}

FAQs

Package last updated on 13 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts