imessage

package
v0.0.0-...-55d53d3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownNormalTapbackTarget = errors.New("unrecognized formatting of normal tapback target")
	ErrInvalidTapbackTargetPart   = errors.New("tapback target part index is invalid")
	ErrUnknownTapbackTargetType   = errors.New("unrecognized tapback target type")
)
View Source
var AppleEpoch = time.Date(2001, 1, 1, 0, 0, 0, 0, time.UTC)
View Source
var (
	ErrNotLoggedIn = errors.New("you're not logged into iMessage")
)
View Source
var Implementations = make(map[string]func(Bridge) (API, error))
View Source
var TempDirPermissions os.FileMode = 0700
View Source
var TempFilePermissions os.FileMode = 0640

Functions

func SendFilePrepare

func SendFilePrepare(filename string, data []byte) (string, string, error)

func TempDir

func TempDir(name string) (string, error)

Types

type API

type API interface {
	Start(readyCallback func()) error
	Stop()
	GetMessagesSinceDate(chatID string, minDate time.Time, backfillID string) ([]*Message, error)
	GetMessagesBetween(chatID string, minDate, maxDate time.Time) ([]*Message, error)
	GetMessagesBeforeWithLimit(chatID string, before time.Time, limit int) ([]*Message, error)
	GetMessagesWithLimit(chatID string, limit int, backfillID string) ([]*Message, error)
	GetChatsWithMessagesAfter(minDate time.Time) ([]ChatIdentifier, error)
	GetMessage(guid string) (*Message, error)
	MessageChan() <-chan *Message
	ReadReceiptChan() <-chan *ReadReceipt
	TypingNotificationChan() <-chan *TypingNotification
	ChatChan() <-chan *ChatInfo
	ContactChan() <-chan *Contact
	MessageStatusChan() <-chan *SendMessageStatus
	BackfillTaskChan() <-chan *BackfillTask
	ContactAPI
	ChatInfoAPI

	ResolveIdentifier(identifier string) (string, error)
	PrepareDM(guid string) error
	CreateGroup(guids []string) (*CreateGroupResponse, error)

	SendMessage(chatID, text string, replyTo string, replyToPart int, richLink *RichLink, metadata MessageMetadata) (*SendResponse, error)
	SendFile(chatID, text, filename string, pathOnDisk string, replyTo string, replyToPart int, mimeType string, voiceMemo bool, metadata MessageMetadata) (*SendResponse, error)
	SendFileCleanup(sendFileDir string)
	SendTapback(chatID, targetGUID string, targetPart int, tapback TapbackType, remove bool) (*SendResponse, error)
	SendReadReceipt(chatID, readUpTo string) error
	SendTypingNotification(chatID string, typing bool) error
	SendMessageBridgeResult(chatID, messageID string, eventID id.EventID, success bool)
	SendBackfillResult(chatID, backfillID string, success bool, idMap map[string][]id.EventID)
	SendChatBridgeResult(guid string, mxid id.RoomID)
	NotifyUpcomingMessage(eventID id.EventID)

	PreStartupSyncHook() (StartupSyncHookResponse, error)
	PostStartupSyncHook()

	Capabilities() ConnectorCapabilities
}

func NewAPI

func NewAPI(bridge Bridge) (API, error)

type Attachment

type Attachment struct {
	GUID       string `json:"guid,omitempty"`
	PathOnDisk string `json:"path_on_disk"`
	FileName   string `json:"file_name"`
	MimeType   string `json:"mime_type,omitempty"`
	// contains filtered or unexported fields
}

func (*Attachment) Delete

func (attachment *Attachment) Delete() error

func (*Attachment) GetFileName

func (attachment *Attachment) GetFileName() string

func (*Attachment) GetMimeType

func (attachment *Attachment) GetMimeType() string

func (*Attachment) Read

func (attachment *Attachment) Read() ([]byte, error)

type BackfillTask

type BackfillTask struct {
	ChatGUID   string     `json:"chat_guid"`
	Messages   []*Message `json:"messages"`
	BackfillID string     `json:"backfill_id"`
}

type Bridge

type Bridge interface {
	GetIPC() *ipc.Processor
	GetLog() log.Logger
	GetZLog() *zerolog.Logger
	GetConnectorConfig() *PlatformConfig
	PingServer() (start, serverTs, end time.Time)
	SendBridgeStatus(state BridgeStatus)
	ReIDPortal(oldGUID, newGUID string, mergeExisting bool) bool
	GetMessagesSince(chatGUID string, since time.Time) []string
	SetPushKey(req *PushKeyRequest)
}

type BridgeStatus

type BridgeStatus struct {
	StateEvent string    `json:"state_event"`
	Timestamp  int64     `json:"timestamp"`
	TTL        int       `json:"ttl"`
	Source     string    `json:"source"`
	Error      string    `json:"error,omitempty"`
	Message    string    `json:"message,omitempty"`
	UserID     id.UserID `json:"user_id,omitempty"`
	RemoteID   string    `json:"remote_id,omitempty"`
	RemoteName string    `json:"remote_name,omitempty"`

	Info map[string]interface{} `json:"info,omitempty"`
}

type ChatIdentifier

type ChatIdentifier struct {
	ChatGUID string `json:"chat_guid"`
	ThreadID string `json:"thread_id,omitempty"`
}

type ChatInfo

type ChatInfo struct {
	JSONChatGUID string `json:"chat_guid"`
	Identifier   `json:"-"`
	DisplayName  string   `json:"title"`
	Members      []string `json:"members"`
	NoCreateRoom bool     `json:"no_create_room"`
	ThreadID     string   `json:"thread_id,omitempty"`
	Delete       bool     `json:"delete,omitempty"`
}

type ChatInfoAPI

type ChatInfoAPI interface {
	GetChatInfo(chatID, threadID string) (*ChatInfo, error)
	GetGroupAvatar(chatID string) (*Attachment, error)
}

type ConnectorCapabilities

type ConnectorCapabilities struct {
	MessageSendResponses     bool
	SendTapbacks             bool
	SendReadReceipts         bool
	SendTypingNotifications  bool
	SendCaptions             bool
	UnsendMessages           bool
	EditMessages             bool
	BridgeState              bool
	MessageStatusCheckpoints bool
	DeliveredStatus          bool
	ContactChatMerging       bool
	RichLinks                bool
	ChatBridgeResult         bool
}

type Contact

type Contact struct {
	FirstName string   `json:"first_name,omitempty"`
	LastName  string   `json:"last_name,omitempty"`
	Nickname  string   `json:"nickname,omitempty"`
	Avatar    []byte   `json:"avatar,omitempty"`
	Phones    []string `json:"phones,omitempty"`
	Emails    []string `json:"emails,omitempty"`
	UserGUID  string   `json:"user_guid,omitempty"`

	PrimaryIdentifier string `json:"primary_identifier,omitempty"`
}

func (*Contact) HasName

func (contact *Contact) HasName() bool

func (*Contact) Name

func (contact *Contact) Name() string

type ContactAPI

type ContactAPI interface {
	GetContactInfo(identifier string) (*Contact, error)
	GetContactList() ([]*Contact, error)
	SearchContactList(searchTerms string) ([]*Contact, error)
	RefreshContactList() error
}

type CreateGroupResponse

type CreateGroupResponse struct {
	GUID     string `json:"guid"`
	ThreadID string `json:"thread_id"`
}

type GroupActionType

type GroupActionType int
const (
	GroupActionAddUser    GroupActionType = 0
	GroupActionRemoveUser GroupActionType = 1

	GroupActionSetAvatar    GroupActionType = 1
	GroupActionRemoveAvatar GroupActionType = 2
)

type Identifier

type Identifier struct {
	LocalID string
	Service string

	IsGroup bool
}

func ParseIdentifier

func ParseIdentifier(guid string) Identifier

func (Identifier) String

func (id Identifier) String() string

type ItemType

type ItemType int
const (
	ItemTypeMessage ItemType = iota
	ItemTypeMember
	ItemTypeName
	ItemTypeAvatar

	ItemTypeError ItemType = -100
)

type Message

type Message struct {
	RowID int `json:"-"`

	GUID           string     `json:"guid"`
	Time           time.Time  `json:"-"`
	JSONUnixTime   float64    `json:"timestamp"`
	Subject        string     `json:"subject"`
	Text           string     `json:"text"`
	ChatGUID       string     `json:"chat_guid"`
	JSONSenderGUID string     `json:"sender_guid"`
	Sender         Identifier `json:"-"`
	JSONTargetGUID string     `json:"target_guid"`
	Target         Identifier `json:"-"`

	// The service from the sender_guid is extracted and stored here.
	Service string `json:"service"`

	IsFromMe       bool      `json:"is_from_me"`
	IsRead         bool      `json:"is_read"`
	ReadAt         time.Time `json:"-"`
	JSONUnixReadAt float64   `json:"read_at"`
	IsDelivered    bool
	IsSent         bool
	IsEmote        bool
	IsAudioMessage bool `json:"is_audio_message"`
	IsEdited       bool
	IsRetracted    bool

	ReplyToGUID string   `json:"thread_originator_guid,omitempty"`
	ReplyToPart int      `json:"thread_originator_part,omitempty"`
	Tapback     *Tapback `json:"associated_message,omitempty"`

	ReplyProcessed bool `json:"-"`

	// Deprecated: use attachments array
	Attachment *Attachment `json:"attachment,omitempty"`

	Attachments []*Attachment `json:"attachments,omitempty"`

	ErrorNotice string `json:"error_notice,omitempty"`

	ItemType        ItemType        `json:"item_type,omitempty"`
	GroupActionType GroupActionType `json:"group_action_type,omitempty"`
	NewGroupName    string          `json:"new_group_title,omitempty"`

	RichLink *RichLink `json:"rich_link,omitempty"`

	Metadata MessageMetadata `json:"metadata,omitempty"`

	ThreadID string `json:"thread_id,omitempty"`
}

func (*Message) SenderText

func (msg *Message) SenderText() string

type MessageMetadata

type MessageMetadata = map[string]interface{}

type PlatformConfig

type PlatformConfig struct {
	Platform string `yaml:"platform"`

	IMRestPath     string   `yaml:"imessage_rest_path"`
	IMRestArgs     []string `yaml:"imessage_rest_args"`
	ContactsMode   string   `yaml:"contacts_mode"`
	HackySetLocale string   `yaml:"hacky_set_locale"`
	Environment    []string `yaml:"environment"`
	LogIPCPayloads bool     `yaml:"log_ipc_payloads"`
	UnixSocket     string   `yaml:"unix_socket"`

	PingInterval int64 `yaml:"ping_interval_seconds"`

	DeleteMediaAfterUpload bool `yaml:"delete_media_after_upload"`

	BlueBubblesURL      string `yaml:"bluebubbles_url"`
	BlueBubblesPassword string `yaml:"bluebubbles_password"`
}

func (*PlatformConfig) BridgeName

func (pc *PlatformConfig) BridgeName() string

type PushKeyRequest

type PushKeyRequest struct {
	URL string `json:"url"`

	AppID     string `json:"app_id"`
	PushKey   string `json:"pushkey"`
	PushKeyTS int64  `json:"pushkey_ts"`

	Data map[string]interface{} `json:"data"`
}

type ReadReceipt

type ReadReceipt struct {
	SenderGUID string `json:"sender_guid"`
	IsFromMe   bool   `json:"is_from_me"`
	ChatGUID   string `json:"chat_guid"`
	ReadUpTo   string `json:"read_up_to"`

	ReadAt         time.Time `json:"-"`
	JSONUnixReadAt float64   `json:"read_at"`
}
type RichLink struct {
	OriginalURL            string              `json:"originalURL,omitempty"`
	URL                    string              `json:"URL,omitempty"`
	Title                  string              `json:"title,omitempty"`
	Summary                string              `json:"summary,omitempty"`
	SelectedText           string              `json:"selectedText,omitempty"`
	SiteName               string              `json:"siteName,omitempty"`
	RelatedURL             string              `json:"relatedURL,omitempty"`
	Creator                string              `json:"creator,omitempty"`
	CreatorFacebookProfile string              `json:"creatorFacebookProfile,omitempty"`
	CreatorTwitterUsername string              `json:"creatorTwitterUsername,omitempty"`
	ItemType               string              `json:"itemType,omitempty"`
	Icon                   *RichLinkAsset      `json:"icon,omitempty"`
	Image                  *RichLinkAsset      `json:"image,omitempty"`
	Video                  *RichLinkVideoAsset `json:"video,omitempty"`
	Audio                  *RichLinkAsset      `json:"audio,omitempty"`
	Images                 []RichLinkAsset     `json:"images,omitempty"`
	Videos                 []RichLinkAsset     `json:"videos,omitempty"`
	StreamingVideos        []RichLinkAsset     `json:"streamingVideos,omitempty"`
	Audios                 []RichLinkAsset     `json:"audios,omitempty"`
}

type RichLinkAsset

type RichLinkAsset struct {
	MimeType          string               `json:"mimeType,omitempty"`
	AccessibilityText string               `json:"accessibilityText,omitempty"`
	Source            *RichLinkAssetSource `json:"source,omitempty"`
	OriginalURL       string               `json:"originalURL,omitempty"`
	Size              *RichLinkAssetSize   `json:"size,omitempty"`
}

type RichLinkAssetSize

type RichLinkAssetSize struct {
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type RichLinkAssetSource

type RichLinkAssetSource struct {
	URL  string `json:"url,omitempty"`
	Data []byte `json:"data,omitempty"`
}

type RichLinkVideoAsset

type RichLinkVideoAsset struct {
	HasAudio     bool          `json:"hasAudio,omitempty"`
	YouTubeURL   string        `json:"youTubeURL,omitempty"`
	StreamingURL string        `json:"streamingURL,omitempty"`
	Asset        RichLinkAsset `json:"asset"`
}

type SendMessageStatus

type SendMessageStatus struct {
	GUID       string `json:"guid"`
	ChatGUID   string `json:"chat_guid"`
	Status     string `json:"status"`
	Service    string `json:"service"`
	Message    string `json:"message,omitempty"`
	StatusCode string `json:"status_code,omitempty"`
}

type SendResponse

type SendResponse struct {
	GUID     string    `json:"guid"`
	Service  string    `json:"service"`
	ChatGUID string    `json:"chat_guid"`
	Time     time.Time `json:"-"`
	UnixTime float64   `json:"timestamp"`
}

type StartupSyncHookResponse

type StartupSyncHookResponse struct {
	SkipSync bool `json:"skip_sync"`
}

type Tapback

type Tapback struct {
	TargetGUID string      `json:"target_guid"`
	TargetPart int         `json:"-"`
	Remove     bool        `json:"-"`
	Type       TapbackType `json:"type"`
}

func (*Tapback) Parse

func (tapback *Tapback) Parse() (*Tapback, error)

type TapbackType

type TapbackType int
const (
	TapbackLove TapbackType = iota + 2000
	TapbackLike
	TapbackDislike
	TapbackLaugh
	TapbackEmphasis
	TapbackQuestion

	TapbackRemoveOffset = 1000
)

func TapbackFromEmoji

func TapbackFromEmoji(emoji string) TapbackType

func TapbackFromName

func TapbackFromName(name string) TapbackType

func (TapbackType) Emoji

func (amt TapbackType) Emoji() string

func (TapbackType) Name

func (amt TapbackType) Name() string

func (TapbackType) String

func (amt TapbackType) String() string

type TypingNotification

type TypingNotification struct {
	ChatGUID string `json:"chat_guid"`
	Typing   bool   `json:"typing"`
}

type VenturaFeatures

type VenturaFeatures interface {
	UnsendMessage(chatID, targetGUID string, targetPart int) (*SendResponse, error)
	EditMessage(chatID, targetGUID string, newText string, targetPart int) (*SendResponse, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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