telegram

package
v0.0.0-...-fb315dc Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 31 Imported by: 0

README

The service provides a mechaism to communicate directly with telegram

Environment Variables

HAL_API_SERVICES - Audit endpoint to send all messages too.

Admin

HAL exposes a number of API's that allow the user to configure how the bot can assist your group.

The admin services require a JWT Token. There are 2 ways to obtain the token

Telegram Commands

execute command /jwt and a JWT token will be returned that can be used to admin the group functions. The token is only valid for the group in which is was created.

API

Auditing

HAL has been designed to allow for all messages to be send to an audit endpoint.

The following are available:

Documentation

Overview

Package mock_telegram is a generated GoMock package.

Package mock_telegram is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomClaimFactory

func CustomClaimFactory() jwt.Claims

func Escape

func Escape(request string) string

func MakeHandler

func MakeHandler(service Service, logger kitlog.Logger, ml machineLearning.Service) http.Handler

MakeHandler returns a HTTP Restul endpoint to handle user requests

Types

type Command

type Command interface {
	CommandIdentifier() string
	CommandDescription() string
	RestrictToAuthorised() bool
	Show(chat uint32) bool
	Execute(ctx context.Context, update tgbotapi.Update)
}

func NewHelpCommand

func NewHelpCommand(telegram Service, store Store) Command

func NewIDCommand

func NewIDCommand(telegram Service, store Store) Command

func NewTokenCommand

func NewTokenCommand(service Service, store Store) Command

type Commandlet

type Commandlet interface {
	CanExecute(update tgbotapi.Update, state State) bool
	Execute(ctx context.Context, update tgbotapi.Update, state State)
	NextState(update tgbotapi.Update, state State) string
	Fields(update tgbotapi.Update, state State) []string
}

func NewTelegramAuthApprovalCommand

func NewTelegramAuthApprovalCommand(service2 Service, store Store) Commandlet

type CustomClaims

type CustomClaims struct {
	RoomToken uint32 `json:"roomToken"`
	jwt.StandardClaims
}

type MockService

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

MockService is a mock of Service interface

func NewMockService

func NewMockService(ctrl *gomock.Controller) *MockService

NewMockService creates a new mock instance

func (*MockService) EXPECT

func (m *MockService) EXPECT() *MockServiceMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockService) RegisterCommand

func (m *MockService) RegisterCommand(arg0 Command)

RegisterCommand mocks base method

func (*MockService) RegisterCommandLet

func (m *MockService) RegisterCommandLet(arg0 Commandlet)

RegisterCommandLet mocks base method

func (*MockService) SendDocumentToGroup

func (m *MockService) SendDocumentToGroup(arg0 context.Context, arg1 []byte, arg2 string, arg3 int64) error

SendDocumentToGroup mocks base method

func (*MockService) SendImageToGroup

func (m *MockService) SendImageToGroup(arg0 context.Context, arg1 []byte, arg2 int64) error

SendImageToGroup mocks base method

func (*MockService) SendKeyboard

func (m *MockService) SendKeyboard(arg0 context.Context, arg1 []string, arg2 string, arg3 int64) (int, error)

SendKeyboard mocks base method

func (*MockService) SendMessage

func (m *MockService) SendMessage(arg0 context.Context, arg1 int64, arg2 string, arg3 int) (int, error)

SendMessage mocks base method

func (*MockService) SendMessagePlainText

func (m *MockService) SendMessagePlainText(arg0 context.Context, arg1 int64, arg2 string, arg3 int) (int, error)

SendMessagePlainText mocks base method

func (*MockService) SendMessageWithCorrelation

func (m *MockService) SendMessageWithCorrelation(arg0 context.Context, arg1 int64, arg2 string, arg3 int, arg4 string) (int, error)

SendMessageWithCorrelation mocks base method

type MockServiceMockRecorder

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

MockServiceMockRecorder is the mock recorder for MockService

func (*MockServiceMockRecorder) RegisterCommand

func (mr *MockServiceMockRecorder) RegisterCommand(arg0 interface{}) *gomock.Call

RegisterCommand indicates an expected call of RegisterCommand

func (*MockServiceMockRecorder) RegisterCommandLet

func (mr *MockServiceMockRecorder) RegisterCommandLet(arg0 interface{}) *gomock.Call

RegisterCommandLet indicates an expected call of RegisterCommandLet

func (*MockServiceMockRecorder) SendDocumentToGroup

func (mr *MockServiceMockRecorder) SendDocumentToGroup(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

SendDocumentToGroup indicates an expected call of SendDocumentToGroup

func (*MockServiceMockRecorder) SendImageToGroup

func (mr *MockServiceMockRecorder) SendImageToGroup(arg0, arg1, arg2 interface{}) *gomock.Call

SendImageToGroup indicates an expected call of SendImageToGroup

func (*MockServiceMockRecorder) SendKeyboard

func (mr *MockServiceMockRecorder) SendKeyboard(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

SendKeyboard indicates an expected call of SendKeyboard

func (*MockServiceMockRecorder) SendMessage

func (mr *MockServiceMockRecorder) SendMessage(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

SendMessage indicates an expected call of SendMessage

func (*MockServiceMockRecorder) SendMessagePlainText

func (mr *MockServiceMockRecorder) SendMessagePlainText(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

SendMessagePlainText indicates an expected call of SendMessagePlainText

func (*MockServiceMockRecorder) SendMessageWithCorrelation

func (mr *MockServiceMockRecorder) SendMessageWithCorrelation(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call

SendMessageWithCorrelation indicates an expected call of SendMessageWithCorrelation

type MockStore

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

MockStore is a mock of Store interface

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

NewMockStore creates a new mock instance

func (*MockStore) AcknowledgeReply

func (m *MockStore) AcknowledgeReply(id bson.ObjectId) error

AcknowledgeReply mocks base method

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStore) GetReplies

func (m *MockStore) GetReplies(chat int64) ([]Replies, error)

GetReplies mocks base method

func (*MockStore) GetRoomKey

func (m *MockStore) GetRoomKey(chat uint32) (int64, error)

GetRoomKey mocks base method

func (*MockStore) GetUUID

func (m *MockStore) GetUUID(chat int64, name string) (uint32, error)

GetUUID mocks base method

func (*MockStore) SaveReply

func (m *MockStore) SaveReply(chat int64, message, correlationId string) error

SaveReply mocks base method

func (*MockStore) SetState

func (m *MockStore) SetState(user int, chat int64, state string, field []string) error

SetState mocks base method

type MockStoreMockRecorder

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

MockStoreMockRecorder is the mock recorder for MockStore

func (*MockStoreMockRecorder) AcknowledgeReply

func (mr *MockStoreMockRecorder) AcknowledgeReply(id interface{}) *gomock.Call

AcknowledgeReply indicates an expected call of AcknowledgeReply

func (*MockStoreMockRecorder) GetReplies

func (mr *MockStoreMockRecorder) GetReplies(chat interface{}) *gomock.Call

GetReplies indicates an expected call of GetReplies

func (*MockStoreMockRecorder) GetRoomKey

func (mr *MockStoreMockRecorder) GetRoomKey(chat interface{}) *gomock.Call

GetRoomKey indicates an expected call of GetRoomKey

func (*MockStoreMockRecorder) GetUUID

func (mr *MockStoreMockRecorder) GetUUID(chat, name interface{}) *gomock.Call

GetUUID indicates an expected call of GetUUID

func (*MockStoreMockRecorder) SaveReply

func (mr *MockStoreMockRecorder) SaveReply(chat, message, correlationId interface{}) *gomock.Call

SaveReply indicates an expected call of SaveReply

func (*MockStoreMockRecorder) SetState

func (mr *MockStoreMockRecorder) SetState(user, chat, state, field interface{}) *gomock.Call

SetState indicates an expected call of SetState

type RemoteCommand

type RemoteCommand interface {
	GetCommandGroup() uint32
}

type Replies

type Replies struct {
	ID            bson.ObjectId `bson:"_id,omitempty"`
	CorrelationId string
	ChatId        int64 `bson:"chatId"`
	Message       string
}

type Service

type Service interface {
	SendMessage(ctx context.Context, chatID int64, message string, messageID int) (msgid int, err error)
	SendMessageWithCorrelation(ctx context.Context, chatID int64, message string, messageID int, correlationId string) (msgid int, err error)
	SendMessagePlainText(ctx context.Context, chatID int64, message string, messageID int) (msgid int, err error)
	SendImageToGroup(ctx context.Context, image []byte, group int64) error
	SendDocumentToGroup(ctx context.Context, document []byte, extension string, group int64) error

	SendKeyboard(ctx context.Context, buttons []string, text string, chat int64) (int, error)
	RegisterCommand(command Command)
	RegisterCommandLet(commandlet Commandlet)
	// contains filtered or unexported methods
}

func NewInstrumentService

func NewInstrumentService(counter metrics.Counter, errorCount metrics.Counter, latency metrics.Histogram, s Service) Service

func NewLoggingService

func NewLoggingService(logger log.Logger, s Service) Service

func NewMachineLearning

func NewMachineLearning(service machineLearning.Service, s Service) Service

NewMachineLearning returns a decorated Service object that will log the telegram actions executed to the machine learning database

func NewService

func NewService(store Store, authService auth.Service) Service

type State

type State struct {
	Userid int
	ChatId int64
	State  string
	Field  []string
}

State is the current user state when flowing through a multi step process.

type Store

type Store interface {
	SetState(user int, chat int64, state string, field []string) error

	GetRoomKey(chat uint32) (roomid int64, err error)
	GetUUID(chat int64, name string) (uuid uint32, err error)

	SaveReply(chat int64, message string, correlationId string) error
	GetReplies(chat int64) ([]Replies, error)
	AcknowledgeReply(id bson.ObjectId) error
	// contains filtered or unexported methods
}

func NewMongoStore

func NewMongoStore(mongo *mgo.Database) Store

Jump to

Keyboard shortcuts

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