telegram

package
v1.0.68 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TelegramMsg

type TelegramMsg struct {
	ChatID      int64  `json:"chat_id"`
	Message     string `json:"message"`
	FileURL     string `json:"file_url"`
	FileCaption string `json:"file_caption"`
	MimeType    string `json:"mime_type"`
	Save        bool   `json:"save"`
	Data        *models.TelegramMessage
}

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.

Jump to

Keyboard shortcuts

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