Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

don't send message to new Instagram followers instantly #250

Closed
dlgchg opened this issue Jun 18, 2019 · 2 comments
Closed

don't send message to new Instagram followers instantly #250

dlgchg opened this issue Jun 18, 2019 · 2 comments

Comments

@dlgchg
Copy link

dlgchg commented Jun 18, 2019

this is my code.

func Send2(insta *Instagram, user User, text, id string) error {
	ids := make([][]int64, 0)
	ids = append(ids, []int64{user.ID})
	bytes, err := json.Marshal(ids)
	if err != nil {
		return err
	}
	to := b2s(bytes)
	thread, err := json.Marshal([]string{id})
	if err != nil {
		return err
	}
	log.Println(b2s(thread))
	data := insta.prepareDataQuery(
		map[string]interface{}{
			"recipient_users": to,
			"client_context":  generateUUID(),
			"thread_ids":      b2s(thread),
			"action":          "send_item",
			"text":            text,
		},
	)
	_, err = insta.sendRequest(
		&reqOptions{
			Connection: "keep-alive",
			Endpoint:   urlInboxSend,
			Query:      data,
			IsPost:     true,
		},
	)
	return err
}

this source code。

func (c *Conversation) Send(text string) error {
	insta := c.inst
	// I DON'T KNOW WHY BUT INSTAGRAM WANTS A DOUBLE SLICE OF INTS FOR ONE ID.
	to, err := prepareRecipients(c)
	if err != nil {
		return err
	}

	// I DONT KNOW WHY BUT INSTAGRAM WANTS SLICE OF STRINGS FOR ONE ID
	thread, err := json.Marshal([]string{c.ID})
	if err != nil {
		return err
	}

	data := insta.prepareDataQuery(
		map[string]interface{}{
			"recipient_users": to,
			"client_context":  generateUUID(),
			"thread_ids":      b2s(thread),
			"action":          "send_item",
			"text":            text,
		},
	)
	_, err = insta.sendRequest(
		&reqOptions{
			Connection: "keep-alive",
			Endpoint:   urlInboxSend,
			Query:      data,
			IsPost:     true,
		},
	)
	return err
}

thread_ids, random or rule ?

@issue-label-bot
Copy link

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

@dlgchg dlgchg closed this as completed Jun 18, 2019
@ahmdrz
Copy link
Owner

ahmdrz commented Jun 19, 2019

The thread_id is one of your direct chat items.
For example, if person_a send a direct message to person_b, thread_id for person_a is person_b.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants