Documentation
¶
Index ¶
- Variables
- func SupportsImages(model OpenAIModel) bool
- type AudioHandler
- type ContactHandler
- type DocumentHandler
- type FallbackHandler
- type GPTBotConfig
- type GPTSessionData
- type ImageHandler
- type LocationHandler
- type MessageHandler
- type OpenAIModel
- type PollHandler
- type PollUpdateHandler
- type ProcessMessageMiddleware
- type ProcessResponseMiddleware
- type TextHandler
- type VideoHandler
- type WhatsappGptBot
- func (bot *WhatsappGptBot) AddMessageMiddleware(middleware ProcessMessageMiddleware)
- func (bot *WhatsappGptBot) AddResponseMiddleware(middleware ProcessResponseMiddleware)
- func (bot *WhatsappGptBot) GetModel() OpenAIModel
- func (bot *WhatsappGptBot) GetOpenAI() *openai.Client
- func (bot *WhatsappGptBot) GetSystemMessage() string
- func (bot *WhatsappGptBot) ProcessMessage(ctx context.Context, notification *whatsapp_chatbot_golang.Notification, ...) (string, *GPTSessionData, error)
- func (bot *WhatsappGptBot) RegisterMessageHandler(handler MessageHandler)
- func (bot *WhatsappGptBot) SupportsImages() bool
Constants ¶
This section is empty.
Variables ¶
var ImageCapableModels = map[OpenAIModel]bool{ ModelGPT4o: true, ModelGPT4oMini: true, ModelGPT4Turbo: true, }
ImageCapableModels lists models known to support image input.
Functions ¶
func SupportsImages ¶
func SupportsImages(model OpenAIModel) bool
SupportsImages checks if a model supports image processing based on the known list.
Types ¶
type AudioHandler ¶
type AudioHandler struct{}
AudioHandler handles audio/voice messages
func (*AudioHandler) CanHandle ¶
func (h *AudioHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is an audio message
func (*AudioHandler) ProcessMessage ¶
func (h *AudioHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, client *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes an audio message
type ContactHandler ¶
type ContactHandler struct{}
ContactHandler handles contact messages
func (*ContactHandler) CanHandle ¶
func (h *ContactHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a contact message
func (*ContactHandler) ProcessMessage ¶
func (h *ContactHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a contact message
type DocumentHandler ¶
type DocumentHandler struct{}
DocumentHandler handles document messages
func (*DocumentHandler) CanHandle ¶
func (h *DocumentHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a document message
func (*DocumentHandler) ProcessMessage ¶
func (h *DocumentHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a document message
type FallbackHandler ¶
type FallbackHandler struct{}
FallbackHandler handles unsupported message types
func (*FallbackHandler) CanHandle ¶
func (h *FallbackHandler) CanHandle(_ *whatsapp_chatbot_golang.Notification) bool
CanHandle always returns true as this is the fallback handler
func (*FallbackHandler) ProcessMessage ¶
func (h *FallbackHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage provides a fallback message for unsupported types
type GPTBotConfig ¶
type GPTBotConfig struct { // OpenAI API key OpenAIApiKey string // Model to use (default: gpt-4o) Model OpenAIModel // Maximum number of messages to keep in history MaxHistoryLength int // System message to set the bot's personality SystemMessage string // Temperature for response generation Temperature float32 // Error message to show when something goes wrong ErrorMessage string // ID Instance from GREEN-API IDInstance string // API Token Instance from GREEN-API APITokenInstance string // Whether to clear webhook queue on start ClearWebhookQueueOnStart bool }
GPTBotConfig contains configuration for the GPT bot
type GPTSessionData ¶
type GPTSessionData struct { // Messages in the conversation Messages []openai.ChatCompletionMessage `json:"messages"` // Timestamp of last activity LastActivity int64 `json:"lastActivity"` // Custom user data UserData map[string]interface{} `json:"userData,omitempty"` // Context for the current conversation Context map[string]interface{} `json:"context,omitempty"` }
GPTSessionData contains conversation history and model settings
type ImageHandler ¶
type ImageHandler struct{}
ImageHandler handles image messages
func (*ImageHandler) CanHandle ¶
func (h *ImageHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is an image message
func (*ImageHandler) ProcessMessage ¶
func (h *ImageHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, model OpenAIModel) (interface{}, error)
ProcessMessage processes an image message
type LocationHandler ¶
type LocationHandler struct{}
LocationHandler handles location messages
func (*LocationHandler) CanHandle ¶
func (h *LocationHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a location message
func (*LocationHandler) ProcessMessage ¶
func (h *LocationHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a location message
type MessageHandler ¶
type MessageHandler interface { CanHandle(notification *whatsapp_chatbot_golang.Notification) bool ProcessMessage(notification *whatsapp_chatbot_golang.Notification, client *openai.Client, model OpenAIModel) (interface{}, error) }
MessageHandler interface for processing different message types
type OpenAIModel ¶
type OpenAIModel string
OpenAIModel represents an OpenAI model identifier
const ( ModelGPT4 OpenAIModel = "gpt-4" ModelGPT4Turbo OpenAIModel = "gpt-4-turbo" ModelGPT4TurboPreview OpenAIModel = "gpt-4-turbo-preview" ModelGPT41106Preview OpenAIModel = "gpt-4-1106-preview" ModelGPT40125Preview OpenAIModel = "gpt-4-0125-preview" ModelGPT432k OpenAIModel = "gpt-4-32k" ModelGPT4o OpenAIModel = "gpt-4o" ModelGPT4oMini OpenAIModel = "gpt-4o-mini" ModelGPT35Turbo OpenAIModel = "gpt-3.5-turbo" ModelGPT35Turbo16k OpenAIModel = "gpt-3.5-turbo-16k" ModelGPT35Turbo1106 OpenAIModel = "gpt-3.5-turbo-1106" ModelGPT35Turbo0125 OpenAIModel = "gpt-3.5-turbo-0125" ModelO1 OpenAIModel = "o1" ModelO1Mini OpenAIModel = "o1-mini" ModelO1Preview OpenAIModel = "o1-preview" DefaultModel = ModelGPT4o )
OpenAI model constants
func (OpenAIModel) String ¶
func (m OpenAIModel) String() string
String returns the string representation of the OpenAIModel.
type PollHandler ¶
type PollHandler struct{}
PollHandler handles incoming poll creation messages
func (*PollHandler) CanHandle ¶
func (h *PollHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a poll creation message
func (*PollHandler) ProcessMessage ¶
func (h *PollHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a poll creation message
type PollUpdateHandler ¶
type PollUpdateHandler struct{}
PollUpdateHandler handles incoming poll update messages
func (*PollUpdateHandler) CanHandle ¶
func (h *PollUpdateHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a poll update message
func (*PollUpdateHandler) ProcessMessage ¶
func (h *PollUpdateHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a poll update message
type ProcessMessageMiddleware ¶
type ProcessMessageMiddleware func(notification *whatsapp_chatbot_golang.Notification, messageContent interface{}, messages []openai.ChatCompletionMessage, sessionData *GPTSessionData) (interface{}, []openai.ChatCompletionMessage, error)
ProcessMessageMiddleware processes a message before sending to GPT
type ProcessResponseMiddleware ¶
type ProcessResponseMiddleware func(response string, messages []openai.ChatCompletionMessage, sessionData *GPTSessionData) (string, []openai.ChatCompletionMessage, error)
ProcessResponseMiddleware processes a response before sending to the user
type TextHandler ¶
type TextHandler struct{}
TextHandler handles text messages
func (*TextHandler) CanHandle ¶
func (h *TextHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a text message
func (*TextHandler) ProcessMessage ¶
func (h *TextHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a text message
type VideoHandler ¶
type VideoHandler struct{}
VideoHandler handles video messages
func (*VideoHandler) CanHandle ¶
func (h *VideoHandler) CanHandle(notification *whatsapp_chatbot_golang.Notification) bool
CanHandle checks if the message is a video message
func (*VideoHandler) ProcessMessage ¶
func (h *VideoHandler) ProcessMessage(notification *whatsapp_chatbot_golang.Notification, _ *openai.Client, _ OpenAIModel) (interface{}, error)
ProcessMessage processes a video message
type WhatsappGptBot ¶
type WhatsappGptBot struct { *whatsapp_chatbot_golang.Bot // contains filtered or unexported fields }
WhatsappGptBot extends the base WhatsApp bot with GPT capabilities
func NewWhatsappGptBot ¶
func NewWhatsappGptBot(config GPTBotConfig) *WhatsappGptBot
NewWhatsappGptBot creates a new GPT-enabled WhatsApp bot
func (*WhatsappGptBot) AddMessageMiddleware ¶
func (bot *WhatsappGptBot) AddMessageMiddleware(middleware ProcessMessageMiddleware)
AddMessageMiddleware registers a middleware to process incoming messages before GPT.
func (*WhatsappGptBot) AddResponseMiddleware ¶
func (bot *WhatsappGptBot) AddResponseMiddleware(middleware ProcessResponseMiddleware)
AddResponseMiddleware registers a middleware to process GPT responses before sending.
func (*WhatsappGptBot) GetModel ¶
func (bot *WhatsappGptBot) GetModel() OpenAIModel
GetModel returns the configured OpenAI model identifier.
func (*WhatsappGptBot) GetOpenAI ¶
func (bot *WhatsappGptBot) GetOpenAI() *openai.Client
GetOpenAI returns the OpenAI client instance for potential custom use.
func (*WhatsappGptBot) GetSystemMessage ¶
func (bot *WhatsappGptBot) GetSystemMessage() string
GetSystemMessage returns the configured system message for the bot.
func (*WhatsappGptBot) ProcessMessage ¶
func (bot *WhatsappGptBot) ProcessMessage(ctx context.Context, notification *whatsapp_chatbot_golang.Notification, sessionData *GPTSessionData) (string, *GPTSessionData, error)
ProcessMessage allows processing a message without using the bot's internal state manager.
func (*WhatsappGptBot) RegisterMessageHandler ¶
func (bot *WhatsappGptBot) RegisterMessageHandler(handler MessageHandler)
RegisterMessageHandler adds a custom message handler.
func (*WhatsappGptBot) SupportsImages ¶
func (bot *WhatsappGptBot) SupportsImages() bool
SupportsImages checks if the currently configured model supports image input.