connector

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WANotLoggedIn      status.BridgeStateErrorCode = "wa-not-logged-in"
	WALoggedOut        status.BridgeStateErrorCode = "wa-logged-out"
	WAMainDeviceGone   status.BridgeStateErrorCode = "wa-main-device-gone"
	WAUnknownLogout    status.BridgeStateErrorCode = "wa-unknown-logout"
	WANotConnected     status.BridgeStateErrorCode = "wa-not-connected"
	WAConnecting       status.BridgeStateErrorCode = "wa-connecting"
	WAKeepaliveTimeout status.BridgeStateErrorCode = "wa-keepalive-timeout"
	WAPhoneOffline     status.BridgeStateErrorCode = "wa-phone-offline"
	WAConnectionFailed status.BridgeStateErrorCode = "wa-connection-failed"
	WADisconnected     status.BridgeStateErrorCode = "wa-transient-disconnect"
	WAStreamReplaced   status.BridgeStateErrorCode = "wa-stream-replaced"
	WAStreamError      status.BridgeStateErrorCode = "wa-stream-error"
	WAClientOutdated   status.BridgeStateErrorCode = "wa-client-outdated"
	WATemporaryBan     status.BridgeStateErrorCode = "wa-temporary-ban"
)
View Source
const (
	LoginStepIDQR          = "fi.mau.whatsapp.login.qr"
	LoginStepIDPhoneNumber = "fi.mau.whatsapp.login.phone"
	LoginStepIDCode        = "fi.mau.whatsapp.login.code"
	LoginStepIDComplete    = "fi.mau.whatsapp.login.complete"

	LoginFlowIDQR    = "qr"
	LoginFlowIDPhone = "phone"
)
View Source
const BroadcastTopic = "WhatsApp broadcast list"
View Source
const EditMaxAge = 15 * time.Minute
View Source
const LoginConnectWait = 15 * time.Second
View Source
const PhoneDisconnectPingTime = 10 * 24 * time.Hour
View Source
const PhoneDisconnectWarningTime = 12 * 24 * time.Hour // 12 days
View Source
const PhoneMinPingInterval = 24 * time.Hour
View Source
const PrivateChatTopic = "WhatsApp private chat"
View Source
const StatusBroadcastName = "WhatsApp Status Broadcast"
View Source
const StatusBroadcastTopic = "WhatsApp status updates from your contacts"
View Source
const UndecryptableMessageNotice = "Decrypting message from WhatsApp failed, waiting for sender to re-send... " +
	"([learn more](https://faq.whatsapp.com/general/security-and-privacy/seeing-waiting-for-this-message-this-may-take-a-while))"
View Source
const UnnamedBroadcastName = "Unnamed broadcast list"
View Source
const WAMaxFileSize = 2000 * 1024 * 1024

Variables

View Source
var (
	ErrLoginClientOutdated = bridgev2.RespError{
		ErrCode:    "FI.MAU.WHATSAPP.CLIENT_OUTDATED",
		Err:        "Got client outdated error while waiting for QRs. The bridge must be updated to continue.",
		StatusCode: http.StatusInternalServerError,
	}
	ErrLoginMultideviceNotEnabled = bridgev2.RespError{
		ErrCode:    "FI.MAU.WHATSAPP.MULTIDEVICE_NOT_ENABLED",
		Err:        "Please enable WhatsApp web multidevice and scan the QR code again.",
		StatusCode: http.StatusBadRequest,
	}
	ErrLoginTimeout = bridgev2.RespError{
		ErrCode:    "FI.MAU.WHATSAPP.LOGIN_TIMEOUT",
		Err:        "Entering code or scanning QR timed out. Please try again.",
		StatusCode: http.StatusBadRequest,
	}
	ErrUnexpectedDisconnect = bridgev2.RespError{
		ErrCode:    "FI.MAU.WHATSAPP.LOGIN_UNEXPECTED_EVENT",
		Err:        "Unexpected event while waiting for login",
		StatusCode: http.StatusInternalServerError,
	}
)
View Source
var ErrBroadcastReactionUnsupported = bridgev2.WrapErrorInStatus(errors.New("reacting to status messages is not currently supported")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
View Source
var ErrBroadcastSendDisabled = bridgev2.WrapErrorInStatus(errors.New("sending status messages is disabled")).WithErrorAsMessage().WithIsCertain(true).WithSendNotice(true).WithErrorReason(event.MessageStatusUnsupported)
View Source
var (
	ErrInputLooksLikeEmail = bridgev2.WrapRespErr(errors.New("WhatsApp only supports phone numbers as user identifiers. Number looks like email"), mautrix.MInvalidParam)
)
View Source
var ErrReloadNeeded = mautrix.RespError{
	ErrCode:    "FI.MAU.WHATSAPP_RELOAD_NEEDED",
	Err:        "Media is no longer available on WhatsApp servers and must be re-requested from your phone",
	StatusCode: http.StatusNotFound,
}
View Source
var ExampleConfig string
View Source
var (
	HelpSectionInvites = commands.HelpSection{Name: "Group invites", Order: 25}
)
View Source
var WhatsAppGeneralCaps = &bridgev2.NetworkGeneralCapabilities{
	DisappearingMessages: true,
	AggressiveUpdateInfo: true,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	OSName      string `yaml:"os_name"`
	BrowserName string `yaml:"browser_name"`

	Proxy          string `yaml:"proxy"`
	GetProxyURL    string `yaml:"get_proxy_url"`
	ProxyOnlyLogin bool   `yaml:"proxy_only_login"`

	DisplaynameTemplate string `yaml:"displayname_template"`

	CallStartNotices            bool          `yaml:"call_start_notices"`
	IdentityChangeNotices       bool          `yaml:"identity_change_notices"`
	SendPresenceOnTyping        bool          `yaml:"send_presence_on_typing"`
	EnableStatusBroadcast       bool          `yaml:"enable_status_broadcast"`
	DisableStatusBroadcastSend  bool          `yaml:"disable_status_broadcast_send"`
	MuteStatusBroadcast         bool          `yaml:"mute_status_broadcast"`
	StatusBroadcastTag          event.RoomTag `yaml:"status_broadcast_tag"`
	PinnedTag                   event.RoomTag `yaml:"pinned_tag"`
	ArchiveTag                  event.RoomTag `yaml:"archive_tag"`
	WhatsappThumbnail           bool          `yaml:"whatsapp_thumbnail"`
	URLPreviews                 bool          `yaml:"url_previews"`
	ExtEvPolls                  bool          `yaml:"extev_polls"`
	DisableViewOnce             bool          `yaml:"disable_view_once"`
	ForceActiveDeliveryReceipts bool          `yaml:"force_active_delivery_receipts"`
	DirectMediaAutoRequest      bool          `yaml:"direct_media_auto_request"`

	AnimatedSticker msgconv.AnimatedStickerConfig `yaml:"animated_sticker"`

	HistorySync struct {
		MaxInitialConversations int  `yaml:"max_initial_conversations"`
		RequestFullSync         bool `yaml:"request_full_sync"`
		FullSyncConfig          struct {
			DaysLimit    uint32 `yaml:"days_limit"`
			SizeLimit    uint32 `yaml:"size_mb_limit"`
			StorageQuota uint32 `yaml:"storage_quota_mb"`
		} `yaml:"full_sync_config"`

		MediaRequests struct {
			AutoRequestMedia bool               `yaml:"auto_request_media"`
			RequestMethod    MediaRequestMethod `yaml:"request_method"`
			RequestLocalTime int                `yaml:"request_local_time"`
			MaxAsyncHandle   int64              `yaml:"max_async_handle"`
		} `yaml:"media_requests"`
	} `yaml:"history_sync"`
	// contains filtered or unexported fields
}

func (*Config) FormatDisplayname

func (c *Config) FormatDisplayname(jid types.JID, contact types.ContactInfo) string

func (*Config) PostProcess added in v0.11.1

func (c *Config) PostProcess() error

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(node *yaml.Node) error

type DisplaynameParams

type DisplaynameParams struct {
	types.ContactInfo
	Phone string

	// Deprecated legacy fields
	JID    string
	Notify string
	VName  string
	Name   string
	Short  string
}

type MediaEditCacheKey

type MediaEditCacheKey struct {
	MessageID  networkid.MessageID
	PortalMXID id.RoomID
}

type MediaEditCacheValue

type MediaEditCacheValue struct {
	Part   *bridgev2.ConvertedMessagePart
	Expiry time.Time
}

type MediaRequestMethod

type MediaRequestMethod string
const (
	MediaRequestMethodImmediate MediaRequestMethod = "immediate"
	MediaRequestMethodLocalTime MediaRequestMethod = "local_time"
)

type MessageInfoWrapper

type MessageInfoWrapper struct {
	Info types.MessageInfo
	// contains filtered or unexported fields
}

func (*MessageInfoWrapper) AddLogContext

func (evt *MessageInfoWrapper) AddLogContext(c zerolog.Context) zerolog.Context

func (*MessageInfoWrapper) GetID

func (evt *MessageInfoWrapper) GetID() networkid.MessageID

func (*MessageInfoWrapper) GetPortalKey

func (evt *MessageInfoWrapper) GetPortalKey() networkid.PortalKey

func (*MessageInfoWrapper) GetSender

func (evt *MessageInfoWrapper) GetSender() bridgev2.EventSender

func (*MessageInfoWrapper) GetTimestamp

func (evt *MessageInfoWrapper) GetTimestamp() time.Time

func (*MessageInfoWrapper) GetTransactionID

func (evt *MessageInfoWrapper) GetTransactionID() networkid.TransactionID

func (*MessageInfoWrapper) ShouldCreatePortal

func (evt *MessageInfoWrapper) ShouldCreatePortal() bool

type WALogin

type WALogin struct {
	User      *bridgev2.User
	Main      *WhatsAppConnector
	Client    *whatsmeow.Client
	Log       zerolog.Logger
	PhoneCode bool
	Timezone  string

	QRs           []string
	StartTime     time.Time
	LoginError    error
	LoginSuccess  *events.PairSuccess
	WaitForQRs    *exsync.Event
	LoginComplete *exsync.Event
	Received515   *exsync.Event
	PrevQRIndex   atomic.Int32

	Closed         atomic.Bool
	EventHandlerID uint32
}

func (*WALogin) Cancel

func (wl *WALogin) Cancel()

func (*WALogin) Start

func (wl *WALogin) Start(ctx context.Context) (*bridgev2.LoginStep, error)

func (*WALogin) SubmitUserInput

func (wl *WALogin) SubmitUserInput(ctx context.Context, input map[string]string) (*bridgev2.LoginStep, error)

func (*WALogin) Wait

func (wl *WALogin) Wait(ctx context.Context) (*bridgev2.LoginStep, error)

type WAMediaRetry

type WAMediaRetry struct {
	*events.MediaRetry
	// contains filtered or unexported fields
}

func (*WAMediaRetry) AddLogContext

func (evt *WAMediaRetry) AddLogContext(c zerolog.Context) zerolog.Context

func (*WAMediaRetry) ConvertEdit

func (evt *WAMediaRetry) ConvertEdit(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, existing []*database.Message) (*bridgev2.ConvertedEdit, error)

func (*WAMediaRetry) GetPortalKey

func (evt *WAMediaRetry) GetPortalKey() networkid.PortalKey

func (*WAMediaRetry) GetSender

func (evt *WAMediaRetry) GetSender() bridgev2.EventSender

func (*WAMediaRetry) GetTargetMessage

func (evt *WAMediaRetry) GetTargetMessage() networkid.MessageID

func (*WAMediaRetry) GetTimestamp

func (evt *WAMediaRetry) GetTimestamp() time.Time

func (*WAMediaRetry) GetType

func (evt *WAMediaRetry) GetType() bridgev2.RemoteEventType

type WAMessageEvent

type WAMessageEvent struct {
	*MessageInfoWrapper
	Message  *waE2E.Message
	MsgEvent *events.Message
	// contains filtered or unexported fields
}

func (*WAMessageEvent) AddLogContext

func (evt *WAMessageEvent) AddLogContext(c zerolog.Context) zerolog.Context

func (*WAMessageEvent) ConvertEdit

func (evt *WAMessageEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, existing []*database.Message) (*bridgev2.ConvertedEdit, error)

func (*WAMessageEvent) ConvertMessage

func (evt *WAMessageEvent) ConvertMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI) (*bridgev2.ConvertedMessage, error)

func (*WAMessageEvent) GetReactionDBMetadata

func (evt *WAMessageEvent) GetReactionDBMetadata() any

func (*WAMessageEvent) GetReactionEmoji

func (evt *WAMessageEvent) GetReactionEmoji() (string, networkid.EmojiID)

func (*WAMessageEvent) GetRemovedEmojiID

func (evt *WAMessageEvent) GetRemovedEmojiID() networkid.EmojiID

func (*WAMessageEvent) GetStreamOrder

func (evt *WAMessageEvent) GetStreamOrder() int64

func (*WAMessageEvent) GetTargetMessage

func (evt *WAMessageEvent) GetTargetMessage() networkid.MessageID

func (*WAMessageEvent) GetType

func (evt *WAMessageEvent) GetType() bridgev2.RemoteEventType

func (*WAMessageEvent) HandleExisting

func (evt *WAMessageEvent) HandleExisting(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, existing []*database.Message) (bridgev2.UpsertResult, error)

func (*WAMessageEvent) PostHandle

func (evt *WAMessageEvent) PostHandle(ctx context.Context, portal *bridgev2.Portal)

type WANowDecryptableMessage

type WANowDecryptableMessage struct {
	*WAMessageEvent
	// contains filtered or unexported fields
}

func (*WANowDecryptableMessage) AddLogContext

func (evt *WANowDecryptableMessage) AddLogContext(c zerolog.Context) zerolog.Context

func (*WANowDecryptableMessage) GetTargetDBMessage

func (evt *WANowDecryptableMessage) GetTargetDBMessage() []*database.Message

func (*WANowDecryptableMessage) GetTargetMessage

func (evt *WANowDecryptableMessage) GetTargetMessage() networkid.MessageID

func (*WANowDecryptableMessage) GetType

type WAUndecryptableMessage

type WAUndecryptableMessage struct {
	*MessageInfoWrapper
	Type events.UnavailableType
}

func (*WAUndecryptableMessage) ConvertMessage

func (evt *WAUndecryptableMessage) ConvertMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI) (*bridgev2.ConvertedMessage, error)

func (*WAUndecryptableMessage) GetStreamOrder

func (evt *WAUndecryptableMessage) GetStreamOrder() int64

func (*WAUndecryptableMessage) GetType

type WhatsAppClient

type WhatsAppClient struct {
	Main      *WhatsAppConnector
	UserLogin *bridgev2.UserLogin
	Client    *whatsmeow.Client
	Device    *store.Device
	JID       types.JID
	// contains filtered or unexported fields
}

func (*WhatsAppClient) Connect

func (wa *WhatsAppClient) Connect(ctx context.Context)

func (*WhatsAppClient) CreateChatWithGhost added in v0.11.2

func (wa *WhatsAppClient) CreateChatWithGhost(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.CreateChatResponse, error)

func (*WhatsAppClient) Disconnect

func (wa *WhatsAppClient) Disconnect()

func (*WhatsAppClient) EnqueueGhostResync

func (wa *WhatsAppClient) EnqueueGhostResync(ghost *bridgev2.Ghost)

func (*WhatsAppClient) EnqueuePortalResync

func (wa *WhatsAppClient) EnqueuePortalResync(portal *bridgev2.Portal)

func (*WhatsAppClient) FetchMessages

func (*WhatsAppClient) GetCapabilities

func (wa *WhatsAppClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities

func (*WhatsAppClient) GetChatInfo

func (wa *WhatsAppClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error)

func (*WhatsAppClient) GetContactList

func (wa *WhatsAppClient) GetContactList(ctx context.Context) ([]*bridgev2.ResolveIdentifierResponse, error)

func (*WhatsAppClient) GetPushConfigs

func (wa *WhatsAppClient) GetPushConfigs() *bridgev2.PushConfig

func (*WhatsAppClient) GetUserInfo

func (wa *WhatsAppClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error)

func (*WhatsAppClient) HandleMatrixEdit

func (wa *WhatsAppClient) HandleMatrixEdit(ctx context.Context, edit *bridgev2.MatrixEdit) error

func (*WhatsAppClient) HandleMatrixMessage

func (*WhatsAppClient) HandleMatrixMessageRemove

func (wa *WhatsAppClient) HandleMatrixMessageRemove(ctx context.Context, msg *bridgev2.MatrixMessageRemove) error

func (*WhatsAppClient) HandleMatrixPollStart

func (wa *WhatsAppClient) HandleMatrixPollStart(ctx context.Context, msg *bridgev2.MatrixPollStart) (*bridgev2.MatrixMessageResponse, error)

func (*WhatsAppClient) HandleMatrixPollVote

func (wa *WhatsAppClient) HandleMatrixPollVote(ctx context.Context, msg *bridgev2.MatrixPollVote) (*bridgev2.MatrixMessageResponse, error)

func (*WhatsAppClient) HandleMatrixReaction

func (wa *WhatsAppClient) HandleMatrixReaction(ctx context.Context, msg *bridgev2.MatrixReaction) (*database.Reaction, error)

func (*WhatsAppClient) HandleMatrixReactionRemove

func (wa *WhatsAppClient) HandleMatrixReactionRemove(ctx context.Context, msg *bridgev2.MatrixReactionRemove) error

func (*WhatsAppClient) HandleMatrixReadReceipt

func (wa *WhatsAppClient) HandleMatrixReadReceipt(ctx context.Context, receipt *bridgev2.MatrixReadReceipt) error

func (*WhatsAppClient) HandleMatrixTyping

func (wa *WhatsAppClient) HandleMatrixTyping(ctx context.Context, msg *bridgev2.MatrixTyping) error

func (*WhatsAppClient) IsLoggedIn

func (wa *WhatsAppClient) IsLoggedIn() bool

func (*WhatsAppClient) IsThisUser

func (wa *WhatsAppClient) IsThisUser(_ context.Context, userID networkid.UserID) bool

func (*WhatsAppClient) LogoutRemote

func (wa *WhatsAppClient) LogoutRemote(ctx context.Context)

func (*WhatsAppClient) PhoneRecentlySeen

func (wa *WhatsAppClient) PhoneRecentlySeen(doPing bool) bool

func (*WhatsAppClient) PreHandleMatrixReaction

func (*WhatsAppClient) RegisterPushNotifications

func (wa *WhatsAppClient) RegisterPushNotifications(ctx context.Context, pushType bridgev2.PushType, token string) error

func (*WhatsAppClient) ResolveIdentifier

func (wa *WhatsAppClient) ResolveIdentifier(ctx context.Context, identifier string, startChat bool) (*bridgev2.ResolveIdentifierResponse, error)

func (*WhatsAppClient) SearchUsers added in v0.11.1

func (wa *WhatsAppClient) SearchUsers(ctx context.Context, query string) ([]*bridgev2.ResolveIdentifierResponse, error)

type WhatsAppConnector

type WhatsAppConnector struct {
	Bridge      *bridgev2.Bridge
	Config      Config
	DeviceStore *sqlstore.Container
	MsgConv     *msgconv.MessageConverter
	DB          *wadb.Database
	// contains filtered or unexported fields
}

func (*WhatsAppConnector) AddMediaEditCache

func (wa *WhatsAppConnector) AddMediaEditCache(portal *bridgev2.Portal, messageID networkid.MessageID, converted *bridgev2.ConvertedMessagePart)

func (*WhatsAppConnector) CreateLogin

func (wa *WhatsAppConnector) CreateLogin(_ context.Context, user *bridgev2.User, flowID string) (bridgev2.LoginProcess, error)

func (*WhatsAppConnector) Download added in v0.11.1

func (wa *WhatsAppConnector) Download(ctx context.Context, mediaID networkid.MediaID, params map[string]string) (mediaproxy.GetMediaResponse, error)

func (*WhatsAppConnector) GetCapabilities

func (wa *WhatsAppConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities

func (*WhatsAppConnector) GetConfig

func (wa *WhatsAppConnector) GetConfig() (string, any, up.Upgrader)

func (*WhatsAppConnector) GetDBMetaTypes

func (wa *WhatsAppConnector) GetDBMetaTypes() database.MetaTypes

func (*WhatsAppConnector) GetLoginFlows

func (wa *WhatsAppConnector) GetLoginFlows() []bridgev2.LoginFlow

func (*WhatsAppConnector) GetMediaEditCache

func (wa *WhatsAppConnector) GetMediaEditCache(portal *bridgev2.Portal, messageID networkid.MessageID) *bridgev2.ConvertedMessagePart

func (*WhatsAppConnector) GetName

func (wa *WhatsAppConnector) GetName() bridgev2.BridgeName

func (*WhatsAppConnector) Init

func (wa *WhatsAppConnector) Init(bridge *bridgev2.Bridge)

func (*WhatsAppConnector) LoadUserLogin

func (wa *WhatsAppConnector) LoadUserLogin(_ context.Context, login *bridgev2.UserLogin) error

func (*WhatsAppConnector) SetMaxFileSize

func (wa *WhatsAppConnector) SetMaxFileSize(maxSize int64)

func (*WhatsAppConnector) SetUseDirectMedia added in v0.11.1

func (wa *WhatsAppConnector) SetUseDirectMedia()

func (*WhatsAppConnector) Start

func (wa *WhatsAppConnector) Start(ctx context.Context) error

func (*WhatsAppConnector) Stop

func (wa *WhatsAppConnector) Stop()

func (*WhatsAppConnector) ValidateUserID added in v0.11.2

func (wa *WhatsAppConnector) ValidateUserID(id networkid.UserID) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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