Skip to content

08. Direct Messaging

David Brouwer edited this page Nov 13, 2021 · 5 revisions

ToDo: still need to write this page

Tldr; You can message through the insta.Inbox struct. Everytime you run the program you need to fetch the messages. If you call Login() for the first time, this will happen automatically. Otherwise, you can do this by either calling OpenApp(), however this will also make a bunch of other calls such as fetch your home & explore page. You might not always want this. Therefore you can also call insta.Inbox.Sync(), this will fetch your inbox for you. To get your pending messages you need to call insta.Inbox.SyncPending()

Interacting with DMs should be pretty intuitive, but for more details please look at the code. If you need more help please push me to write this page.

Inbox:

type Inbox struct {
        Conversations []*Conversation `json:"threads"`
        Pending       []*Conversation `json:"pending"`

        HasNewer            bool   `json:"has_newer"` // TODO
        HasOlder            bool   `json:"has_older"`
        Cursor              string `json:"oldest_cursor"`
        UnseenCount         int    `json:"unseen_count"`
        UnseenCountTs       int64  `json:"unseen_count_ts"`
        MostRecentInviter   User   `json:"most_recent_inviter"`
        BlendedInboxEnabled bool   `json:"blended_inbox_enabled"`
        NextCursor          struct {
                CursorV2ID         float64 `json:"cursor_thread_v2_id"`
                CursorTimestampSec float64 `json:"cursor_timestamp_seconds"`
        } `json:"next_cursor"`
        PrevCursor struct {
                CursorV2ID         float64 `json:"cursor_thread_v2_id"`
                CursorTimestampSec float64 `json:"cursor_timestamp_seconds"`
        } `json:"prev_cursor"`
        SeqID                 int64 `json:"seq_id"`
        PendingRequestsTotal  int   `json:"pending_requests_total"`
        HasPendingTopRequests bool  `json:"has_pending_top_requests"`
        SnapshotAtMs          int64 `json:"snapshot_at_ms"`
}
    Inbox is the direct message inbox.

    Inbox contains Conversations. Each conversation has InboxItems. InboxItems
    are the message of the chat.

func (inbox *Inbox) Error() error
func (inbox *Inbox) InitialSnapshot() bool
func (inbox *Inbox) New(user *User, text string) (*Conversation, error)
func (inbox *Inbox) Next() bool
func (inbox *Inbox) NextPending() bool
func (inbox *Inbox) Reset()
func (inbox *Inbox) Sync() error
func (inbox *Inbox) SyncPending() error

Insta DM Threads, aka Conversation:

type Conversation struct {
        ID   string `json:"thread_id"`
        V2ID string `json:"thread_v2_id"`
        // Items can be of many types.
        Items                      []*InboxItem          `json:"items"`
        Title                      string                `json:"thread_title"`
        Users                      []*User               `json:"users"`
        LeftUsers                  []*User               `json:"left_users"`
        AdminUserIDs               []int64               `json:"admin_user_ids"`
        ApprovalRequiredNewMembers bool                  `json:"approval_required_for_new_members"`
        Pending                    bool                  `json:"pending"`
        PendingScore               int64                 `json:"pending_score"`
        ReshareReceiveCount        int                   `json:"reshare_receive_count"`
        ReshareSendCount           int                   `json:"reshare_send_count"`
        ViewerID                   int64                 `json:"viewer_id"`
        ValuedRequest              bool                  `json:"valued_request"`
        LastActivityAt             int64                 `json:"last_activity_at"`
        Named                      bool                  `json:"named"`
        Muted                      bool                  `json:"muted"`
        Spam                       bool                  `json:"spam"`
        ShhModeEnabled             bool                  `json:"shh_mode_enabled"`
        ShhReplayEnabled           bool                  `json:"shh_replay_enabled"`
        IsPin                      bool                  `json:"is_pin"`
        IsGroup                    bool                  `json:"is_group"`
        IsVerifiedThread           bool                  `json:"is_verified_thread"`
        IsCloseFriendThread        bool                  `json:"is_close_friend_thread"`
        ThreadType                 string                `json:"thread_type"`
        ExpiringMediaSendCount     int                   `json:"expiring_media_send_count"`
        ExpiringMediaReceiveCount  int                   `json:"expiring_media_receive_count"`
        Inviter                    *User                 `json:"inviter"`
        HasOlder                   bool                  `json:"has_older"`
        HasNewer                   bool                  `json:"has_newer"`
        HasRestrictedUser          bool                  `json:"has_restricted_user"`
        Archived                   bool                  `json:"archived"`
        LastSeenAt                 map[string]lastSeenAt `json:"last_seen_at"`
        NewestCursor               string                `json:"newest_cursor"`
        OldestCursor               string                `json:"oldest_cursor"`

        LastPermanentItem InboxItem `json:"last_permanent_item"`
        // Has unexported fields.
}
    Conversation is the representation of an instagram already established
    conversation through direct messages.

func (c *Conversation) Approve() error
func (c *Conversation) Error() error
func (c *Conversation) GetItems() error
func (conv *Conversation) Hide() error
func (c *Conversation) MarkAsSeen(msg InboxItem) error
func (c *Conversation) Next() bool
func (c *Conversation) Refresh() error
func (c *Conversation) Send(text string) error
func (c *Conversation) Write(b []byte) (int, error)
Clone this wiki locally