Documentation
¶
Index ¶
- type TelegramMsg
- type TelegramService
- func (t *TelegramService) CheckSession(resp *models.TGResponse, input *models.ContactModel, ...) (*models.TelegramMessageSession, error)
- func (t *TelegramService) GetFile(fileId string) (map[string]interface{}, error)
- func (t *TelegramService) GetMe() (map[string]interface{}, error)
- func (ws *TelegramService) GetMessageSessionChatBySessionName(sessionName string, contact_id *string, request http.Request) (paginate.Page, error)
- func (ws *TelegramService) GetSessionMessageBySessionName(sessionName string, request http.Request) (paginate.Page, error)
- func (t *TelegramService) GetUserProfilePhotos(userId int64) (map[string]any, error)
- func (t *TelegramService) GetWebhookInfo() (map[string]any, error)
- func (t *TelegramService) SaveMessage(msg *models.TelegramMessage) error
- func (ws *TelegramService) SendCSMessage() (any, error)
- func (t *TelegramService) SendTelegramMessage(input *TelegramMsg) (map[string]any, error)
- func (t *TelegramService) SetInput(input *TelegramMsg)
- func (t *TelegramService) SetToken(botName, token *string)
- func (t *TelegramService) SetWebhook(webhookURL string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TelegramMsg ¶
type TelegramService ¶
type TelegramService struct {
// contains filtered or unexported fields
}
func NewTelegramService ¶
func NewTelegramService(ctx *context.ERPContext) *TelegramService
func (*TelegramService) CheckSession ¶
func (t *TelegramService) CheckSession(resp *models.TGResponse, input *models.ContactModel, connectionID, companyID string) (*models.TelegramMessageSession, error)
func (*TelegramService) GetFile ¶
func (t *TelegramService) GetFile(fileId string) (map[string]interface{}, error)
func (*TelegramService) GetMe ¶
func (t *TelegramService) GetMe() (map[string]interface{}, error)
GetMe retrieves bot information from the Telegram Bot API.
It constructs a request URL with the bot token, then sends a GET request to the Telegram API. Returns a map containing the bot information if successful, or an error if the request fails or the bot credentials are not set.
func (*TelegramService) GetMessageSessionChatBySessionName ¶
func (ws *TelegramService) GetMessageSessionChatBySessionName(sessionName string, contact_id *string, request http.Request) (paginate.Page, error)
GetMessageSessionChatBySessionName retrieves a paginated list of Telegram messages for a specific session and contact.
It takes a session name, an optional contact ID pointer, and an HTTP request as parameters. The function filters messages by session ID and optionally by contact ID. It returns a paginated page of TelegramMessage models and an error if the operation fails.
The function uses request parameters to modify the pagination and filtering behavior.
func (*TelegramService) GetSessionMessageBySessionName ¶
func (ws *TelegramService) GetSessionMessageBySessionName(sessionName string, request http.Request) (paginate.Page, error)
GetSessionMessageBySessionName retrieves a paginated list of Telegram message sessions for a specific session name, search query, and/or tags.
It takes a session name, an optional search query, and an HTTP request as parameters. The function filters message sessions by session name and optionally by search query and tags. It returns a paginated page of TelegramMessageSession models and an error if the operation fails.
The function uses request parameters to modify the pagination and filtering behavior. The following query parameters are supported:
- search: a string to search in the contact's name and email.
- tag_ids: a comma-separated list of tag IDs to filter the results.
- ID-Company: a header to filter the results by company ID. If the header is set to "nil" or "null", only message sessions with a null company ID are returned.
func (*TelegramService) GetUserProfilePhotos ¶
func (t *TelegramService) GetUserProfilePhotos(userId int64) (map[string]any, error)
GetUserProfilePhotos retrieves the user profile photos for the given user ID.
It sends a GET request to the Telegram Bot API to obtain the user profile photos. Returns a map containing the last photo's file information if successful, or an error if the request fails or bot credentials are not set.
func (*TelegramService) GetWebhookInfo ¶
func (t *TelegramService) GetWebhookInfo() (map[string]any, error)
func (*TelegramService) SaveMessage ¶
func (t *TelegramService) SaveMessage(msg *models.TelegramMessage) error
SaveMessage saves a Telegram message to the database.
It takes a pointer to a models.TelegramMessage struct as an argument and returns an error. The function uses the provided context's database connection to create a new record in the telegram_messages table. If the operation fails, it returns the error.
func (*TelegramService) SendCSMessage ¶
func (ws *TelegramService) SendCSMessage() (any, error)
func (*TelegramService) SendTelegramMessage ¶
func (t *TelegramService) SendTelegramMessage(input *TelegramMsg) (map[string]any, error)
SendTelegramMessage sends a message to Telegram.
It takes a TelegramMsg object as input, which must contain a chat ID and a message. If the input specifies a file, it will be sent as a document, photo, audio or video depending on the MIME type.
Returns a map containing the response from the Telegram Bot API, or an error if the request fails.
func (*TelegramService) SetInput ¶
func (t *TelegramService) SetInput(input *TelegramMsg)
SetInput sets the input message for the Telegram service to use in the SendTelegramMessage method.
func (*TelegramService) SetToken ¶
func (t *TelegramService) SetToken(botName, token *string)
func (*TelegramService) SetWebhook ¶
func (t *TelegramService) SetWebhook(webhookURL string) error
SetWebhook sets the webhook for the Telegram bot. It sends a POST request to the Telegram Bot API to set the webhook for the bot. Returns an error if the request fails or bot credentials are not set.