smooch

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Smooch

This is a Go library for making bots with Smooch service.

Tips

Smooch documentation: https://docs.smooch.io/rest/

Installing

$ go get -u github.com/EddyTravels/smooch

Example

import (
	"os"

	"github.com/EddyTravels/smooch"
)

func main() {
    smoochClient, err := smooch.New(smooch.Options{
        AppID:        os.Getenv("SMOOCH_APP_ID"),
        KeyID:        os.Getenv("SMOOCH_KEY_ID"),
        Secret:       os.Getenv("SMOOCH_SECRET"),
        VerifySecret: os.Getenv("SMOOCH_VERIFY_SECRET"),
    })

    if err != nil {
        panic(err)
    }
}

Contributing

You are more than welcome to contribute to this project. Fork and make a Pull Request, or create an Issue if you see any problem.

Documentation

Index

Constants

View Source
const (
	RegionUS = "US"
	RegionEU = "EU"
)
View Source
const (
	MessageTypeText     = MessageType("text")
	MessageTypeImage    = MessageType("image")
	MessageTypeFile     = MessageType("file")
	MessageTypeLocation = MessageType("location")
	MessageTypeCarousel = MessageType("carousel")
	MessageTypeList     = MessageType("list")

	ActionTypePostback        = ActionType("postback")
	ActionTypeReply           = ActionType("reply")
	ActionTypeLocationRequest = ActionType("locationRequest")
	ActionTypeShare           = ActionType("share")
	ActionTypeBuy             = ActionType("buy")
	ActionTypeLink            = ActionType("link")
	ActionTypeWebview         = ActionType("webview")

	SourceTypeWeb       = "web"
	SourceTypeIOS       = "ios"
	SourceTypeAndroid   = "android"
	SourceTypeMessenger = "messenger"
	SourceTypeViber     = "viber"
	SourceTypeTelegram  = "telegram"
	SourceTypeWeChat    = "wechat"
	SourceTypeLine      = "line"
	SourceTypeTwilio    = "twilio"
	SourceTypeApi       = "api"

	RoleAppUser  = Role("appUser")
	RoleAppMaker = Role("appMaker")

	TriggerMessageAppUser  = "message:appUser"
	TriggerMessageAppMaker = "message:appMaker"

	ImageRatioHorizontal = ImageRatio("horizontal")
	ImageRatioSquare     = ImageRatio("square")

	SizeCompact = Size("compact")
	SizeLarge   = Size("large")
)

Variables

View Source
var (
	ErrUserIDEmpty       = errors.New("user id is empty")
	ErrMessageNil        = errors.New("message is nil")
	ErrMessageRoleEmpty  = errors.New("message.Role is empty")
	ErrMessageTypeEmpty  = errors.New("message.Type is empty")
	ErrVerifySecretEmpty = errors.New("verify secret is empty")
)

Functions

func GenerateJWT

func GenerateJWT(scope string, keyID string, secret string) (string, error)

func New

func New(o Options) (*smoochClient, error)

Types

type Action

type Action struct {
	ID       string                 `json:"_id,omitempty"`
	Type     ActionType             `json:"type,omitempty"`
	Text     string                 `json:"text,omitempty"`
	Default  bool                   `json:"default,omitempty"`
	Payload  string                 `json:"payload,omitempty"`
	URI      string                 `json:"uri,omitempty"`
	Amount   int                    `json:"amount,omitempty"`
	Currency string                 `json:"currency,omitempty"`
	State    string                 `json:"state,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

type ActionType

type ActionType string

type AppUser

type AppUser struct {
	ID                  string `json:"_id,omitempty"`
	UserID              string `json:"userId,omitempty"`
	ConversationStarted bool   `json:"conversationStarted,omitempty"`
}

type Application

type Application struct {
	ID string `json:"_id,omitempty"`
}

type Client

type Client interface {
	Handler() http.Handler
	AddWebhookEventHandler(handler WebhookEventHandler)
	Send(userID string, message *Message) (*ResponsePayload, error)
	VerifyRequest(r *http.Request) bool
}

type Conversation

type Conversation struct {
	ID          string `json:"_id"`
	UnreadCount int    `json:"unreadCount,omitempty"`
}

type DisplaySettings

type DisplaySettings struct {
	ImageAspectRatio ImageRatio `json:"imageAspectRatio,omitempty"`
}

type ErrorDetails

type ErrorDetails struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

type ErrorPayload

type ErrorPayload struct {
	Details ErrorDetails `json:"error"`
}

type ImageRatio

type ImageRatio string

type Item

type Item struct {
	ID          string    `json:"_id,omitempty"`
	Title       string    `json:"title,omitempty"`
	Description string    `json:"description,omitempty"`
	Size        Size      `json:"size,omitempty"`
	MediaURL    string    `json:"mediaUrl,omitempty"`
	MediaType   string    `json:"mediaType,omitempty"`
	Actions     []*Action `json:"actions,omitempty"`
}

type Logger

type Logger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
}
type Menu struct {
	Items []*MenuItem `json:"items"`
}
type MenuItem struct {
	ID   string `json:"_id,omitempty"`
	Type string `json:"type,omitempty"`
	Text string `json:"text,omitempty"`
	URI  string `json:"uri,omitempty"`
}
type MenuPayload struct {
	Menu Menu `json:"menu"`
}

type Message

type Message struct {
	ID              string                 `json:"_id,omitempty"`
	Type            MessageType            `json:"type"`
	Text            string                 `json:"text,omitempty"`
	Role            Role                   `json:"role"`
	AuthorID        string                 `json:"authorId,omitempty"`
	Name            string                 `json:"name,omitempty"`
	Received        time.Time              `json:"received,omitempty"`
	Source          *Source                `json:"source,omitempty"`
	MediaUrl        string                 `json:"mediaUrl,omitempty"`
	Actions         []*Action              `json:"actions,omitempty"`
	Items           []*Item                `json:"items,omitempty"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
	DisplaySettings *DisplaySettings       `json:"displaySettings,omitempty"`
}

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type MessageType

type MessageType string

type Options

type Options struct {
	AppID        string
	KeyID        string
	Secret       string
	VerifySecret string
	WebhookURL   string
	Mux          *http.ServeMux
	Logger       Logger
	Region       string
	HttpClient   *http.Client
}

type Payload

type Payload struct {
	Trigger      string       `json:"trigger,omitempty"`
	App          Application  `json:"app,omitempty"`
	Messages     []*Message   `json:"messages,omitempty"`
	AppUser      AppUser      `json:"appUser,omitempty"`
	Conversation Conversation `json:"conversation,omitempty"`
	Version      string       `json:"version,omitempty"`
}

type ResponsePayload

type ResponsePayload struct {
	Message       *Message      `json:"message,omitempty"`
	ExtraMessages []*Message    `json:"extraMessages,omitempty"`
	Conversation  *Conversation `json:"conversation,omitempty"`
}

type Role

type Role string

type Size

type Size string

type SmoochError

type SmoochError struct {
	// contains filtered or unexported fields
}

func (*SmoochError) Code

func (e *SmoochError) Code() int

func (*SmoochError) Error

func (e *SmoochError) Error() string

type Source

type Source struct {
	Type string `json:"type,omitempty"`
}

type WebhookEventHandler

type WebhookEventHandler func(payload *Payload)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL