-
Notifications
You must be signed in to change notification settings - Fork 0
/
botFetch.js
83 lines (71 loc) · 2.2 KB
/
botFetch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const methods = ({ viewer, inbox: { threads } }) => {
const {
pk: user_id,
account_badges: badges,
biz_user_inbox_state: inbox_count,
username,
full_name,
profile_pic_id,
profile_pic_url,
is_verified
} = viewer || {}
return {
user_id, badges, inbox_count, username, full_name, profile_pic_id, profile_pic_url,
threads, is_verified,
getThread(threadId) {
const thread = threads.find(({ thread_id }) => thread_id == threadId)
return thread
},
getMessages(threadId) {
const { items } = this.getThread(threadId)
return items.map(({
client_context: context_id,
item_id: message_id,
item_type: messageType,
text,
timestamp,
user_id,
show_forward_attribution: go_through
}) => ({
context_id,
message_id,
messageType,
text,
timestamp,
user_id,
you: (user_id == this.user_id),
go_through
}))
}
}
}
const getApi = async ig_id => {
const response = await fetch('https://i.instagram.com/api/v1/direct_v2/inbox/?persistentBadging=true&folder=0&cursor=', {
headers: {
accept: '*/*',
'x-ig-app-id': ig_id
},
referrer: 'https://www.instagram.com/',
referrerPolicy: 'strict-origin-when-cross-origin',
body: null,
method: 'GET',
mode: 'cors',
credentials: 'include'
})
const data = await response.json()
return Promise.resolve(data || {})
}
const core = bot => {
const [{ thread_id }] = bot.threads
const thread = bot.getThread(thread_id)
console.log(thread)
const messages = bot.getMessages(thread_id)
console.log(messages)
}
const createBot = async (ig_id) => {
const api = await getApi(ig_id)
const bot = methods(api)
console.log(`Bot ${bot.username} ativo.`)
core(bot)
}
await createBot('936**********59')