Files

35 lines
825 B
Go

package chat
import "context"
const (
Telegram = "telegram"
Email = "email"
)
// Message represents an incoming message from a user.
type Message struct {
// Always should be identifier of the source
// defined as const in this file.
Chat string
// ID is a universal user identifier
// (Telegram chat ID, email, phone, etc).
ID string
// Message contents in form of text.
Text string
}
// Chat defines the complete chat behavior.
// An instance of chat should be able to
// reconnect automatically.
type Chat interface {
// Send delivers a text message to the user identified by ID.
Send(ctx context.Context, id string, text string) error
// Receive returns a channel that emits incoming messages.
// The channel is closed when the context is cancelled.
Receive(ctx context.Context) <-chan Message
}