├── README.md
├── del.py
├── demo.png
├── docid.png
└── others
├── README.md
└── react.py
/README.md:
--------------------------------------------------------------------------------
1 | # Doesn't work anymore from Jan 10 2021
2 | _will try to update the script to make it work with new messsenger updates_
3 |
4 | This script is still in beta version, not because its not working well but because its hard to setup for the first time. But once you set it up, you are ready to go. I will improve this script to set it up by itself in future.
5 |
6 |
7 |
8 | # Setup
9 |
10 | To set it up, you will need to provide 4 values to the script so that this script could perform actions on behalf of you. They are : c_user, xs, fb_dtsg and doc_id. These values doesn't change until your cookie renews. Here's how you could obtain them:
11 |
12 | The value of user and xs can be found in cookies by name c_user and xs respectively.
13 | The dtsg value can be obtained by running this code in messenger.com's console:
14 | ```
15 | var dtsg = require('DTSG').getToken();
16 | alert('Your fb_dtsg token: ' + dtsg);
17 | ```
18 |
19 | To get doc_id value, simply open developer console's network tab in messenger.com and filter out /api/graphqlbatch/. You will probably get 3 results. The required doc_id can be found in the request containing data: batch_name="MessengerGraphQLThreadFetcher" like this:
20 |
21 |
22 |
23 |
24 | @TheBinitGhimire,@nepolian.pratik, @santoshbrl5, @roopeshach
25 | Thank you guys for helping me out =)
26 |
27 | # Alternative
28 |
29 | Alternatively, you can simply paste this script in messenger.com's console:
30 | ```
31 | function ok(){
32 | threedots = document.querySelectorAll("._8sop");
33 | threedotslast = threedots[threedots.length - 1];
34 | threedotslast.click();
35 | removebutton = document.querySelector("._hw5");
36 | removebutton.click();
37 | unsendbutton = document.querySelectorAll("._3quh")[1];
38 | unsendbutton.click();
39 | setTimeout( ok, 1000 );
40 | }
41 | ok(1);
42 | ```
43 | Ofcourse, it is limited and has many issues.
44 |
45 | ## Star History
46 |
47 | [](https://star-history.com/#Prabesh01/fb-message-delete-automation&Date)
48 |
49 | # License
50 |
51 | [](http://creativecommons.org/licenses/by-nc/4.0/)
52 |
--------------------------------------------------------------------------------
/del.py:
--------------------------------------------------------------------------------
1 | import os
2 | import requests
3 | import re
4 | import sys
5 |
6 | #Replace the values with your data
7 | user="enter c_user value from cookie"
8 | xs="enter xs value from cookie"
9 | dtsg="enter fb_dtsg value"
10 | doc="enter doc_id here"
11 |
12 | print('\n')
13 | print('Before running this script, here are few things to consider:\n1) This script if used as it is, will:\n -unsend all your messages,\n -delete the \'you unsent a message\' messages and\n -delete conversation partner\'s messages\n2) If you just want to unsend your messages and nothing else, comment the lines: 98 and 108.\n3) If you want to unsend your messages and also want to remove the \'you unsent a message\' but not delete your partner\'s message, comment the line 108.\n4) If you want to unsend your messages and delete your partner\'s messages, but keep \'you unsent a message\' messages, comment line 98.')
14 | print('\nScript By: Prabesh Sapkota (sapkotaprabesh.github.io | prabeshsapkota.com.np | prabeshsapkota.info.np)')
15 | print('\n\n\n')
16 | continu = input('Press enter to continue..')
17 | print('\n\n\n')
18 |
19 | target=input('Enter target username or profile id (messenger.com/t/????): ')
20 | if type(target) == int:
21 | print('\n')
22 | else:
23 | target = requests.post('https://www.facebook.com/'+target)
24 | target=str(target.text)
25 | poss=re.search("entity_id", target)
26 | if poss==None:
27 | sys.exit('Couldn\'t fetch profile id from username.\n Check if the provided target usename is correct and try again')
28 | target=re.findall("entity_id\":\"................",target)
29 | target=str(target)
30 | target=re.sub(r'\D','',target)
31 |
32 | cookies = {
33 | 'c_user': user,
34 | 'xs': xs,
35 | }
36 |
37 | headers = {
38 | 'Content-Type': 'application/x-www-form-urlencoded, application/x-www-form-urlencoded',
39 | 'User-Agent': 'Mozilla/5.0',
40 | }
41 |
42 | data = {
43 | 'batch_name': 'MessengerGraphQLThreadFetcher',
44 | '__user': user,
45 | '__a': '1',
46 | 'fb_dtsg': dtsg,
47 | 'queries': '{"o0":{"doc_id":'+doc+',"query_params":{"id":'+target+',"message_limit":20000000000000000}}}'
48 | }
49 |
50 | response = requests.post('https://www.messenger.com/api/graphqlbatch/', headers=headers, cookies=cookies, data=data)
51 | out=response.text
52 | #sys.exit(out)
53 | clse=re.search('Please try closing and re-opening your browser window.', out)
54 | if clse!=None:
55 | sys.exit('Please check if the dtsg value is correct.\n If you continuously get this error, uncoment line 53 and run the script again and send me the output at prabesh01@pm.me')
56 | exp=re.search('Please log in to continue.', out)
57 | if exp!=None:
58 | sys.exit("Please check if cookies value is up-to-date.\n If you continuously get this error, uncoment line 53 and run the script again and send me the output at prabesh01@pm.me")
59 | sth=re.search('mid', out)
60 | if sth==None:
61 | sys.exit("Something went wrong, Please try again.\n If you continuously get this error, uncoment line 53 and run the script again and send me the output at prabesh01@pm.me")
62 |
63 | x=re.findall('mid\.\$.............................',out)
64 | x = list(dict.fromkeys(x))
65 | total=len(x)
66 |
67 | for count in reversed(range(total)):
68 | cookies = {
69 | 'c_user': user,
70 | 'xs': xs,
71 | }
72 |
73 | headers = {
74 | 'Content-Type': 'application/x-www-form-urlencoded',
75 | 'User-Agent': 'Mozilla/5.0',
76 | }
77 |
78 | data = {
79 | 'message_id': str(x[count]),
80 | '__user': user,
81 | '__a': '1',
82 | 'fb_dtsg': dtsg
83 | }
84 |
85 | response = requests.post('https://www.messenger.com/messaging/unsend_message/', headers=headers, cookies=cookies, data=data)
86 | last=response.text
87 | den=re.search("errorSummary", last)
88 | if den==None:
89 | print('-\n-\n-\n-\n-\n'+str(count)+'/'+str(total)+":\nDone\n")
90 | data = {
91 | 'message_ids[0]': str(x[count]),
92 | '__user': user,
93 | '__a': '1',
94 | 'fb_dtsg': dtsg
95 | }
96 |
97 | requests.post('https://www.messenger.com/ajax/mercury/delete_messages.php', headers=headers, cookies=cookies, data=data)
98 | if den!=None:
99 | print('-\n-\n-\n-\n-\n'+str(count)+'/'+str(total)+":\nDone\n")
100 | data = {
101 | 'message_ids[0]': str(x[count]),
102 | '__user': user,
103 | '__a': '1',
104 | 'fb_dtsg': dtsg
105 | }
106 |
107 | requests.post('https://www.messenger.com/ajax/mercury/delete_messages.php', headers=headers, cookies=cookies, data=data)
108 |
109 | #for debug purpose:
110 | #print('-\n-\n-\n-\n-\n'+str(count)+'/'+str(total)+":\nRequest:\n"+str(response.request.headers)+'\n'+str(response.request.body)+"\n\nResponse:\n"+str(response.text))
111 | sys.exit('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCompleted Sucessfully!')
112 |
--------------------------------------------------------------------------------
/demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Prabesh01/fb-message-delete-automation/e77c822931c34ebe99148c7e17ed1f7d19cd6ed8/demo.png
--------------------------------------------------------------------------------
/docid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Prabesh01/fb-message-delete-automation/e77c822931c34ebe99148c7e17ed1f7d19cd6ed8/docid.png
--------------------------------------------------------------------------------
/others/README.md:
--------------------------------------------------------------------------------
1 | # React Automation:
2 | It will just react to all the messages of a conversation. The setup is same as the one in del.py expect the doc_id. doc_id is just a request id which is different for different kind of request. Since react needs totally different request than fetching mssg_ids, its doc_id is different. The doc_id is same for all the requests of same kind though.
3 |
4 | ### Setup
5 | As mentioned earlier, the setup is same as in del.py. The only new thing to do is get one more doc_id. The doc_id used in del.py is for fetching messages_id. The doc_id for reacting to the messages is different. To find it, just open messenger.com then fireup burp and intercept req while reacting to any message. You would the get the doc_id in the intercepted request body.
6 |
7 | - Insert the obtained doc_id at line 10 and the doc_id used in del.py (the doc_id for fetching messages_ids) in line 46.
8 |
9 | - Choose what emoji to be used in line 82. Replace 😇 with whatever emozi you want to use. You may copy emoji from here or here
10 |
11 | _In order to reverse the process (i.e. remoove certain emozi from all messages), just replace ADD_REACTION with REMOVE_REACTION in line 82._
12 |
--------------------------------------------------------------------------------
/others/react.py:
--------------------------------------------------------------------------------
1 | import os
2 | import requests
3 | import re
4 | import sys
5 |
6 | #Replace the values with your data
7 | user="enter c_user value from cookie"
8 | xs="enter xs value from cookie"
9 | dtsg="enter fb_dtsg value"
10 | doc="enter react doc_id here""
11 |
12 |
13 | print('\nScript By: Prabesh Sapkota (sapkotaprabesh.github.io | prabeshsapkota.com.np | prabeshsapkota.info.np)')
14 | print('\n\n\n')
15 | continu = input('Press enter to continue..')
16 | print('\n\n\n')
17 |
18 | target=input('Enter target username or profile id (messenger.com/t/????): ')
19 | if type(target) == int:
20 | print('\n')
21 | else:
22 | target = requests.post('https://www.facebook.com/'+target)
23 | target=str(target.text)
24 | poss=re.search("entity_id", target)
25 | if poss==None:
26 | sys.exit('Couldn\'t fetch profile id from username.\n Check if the provided target usename is correct and try again')
27 | target=re.findall("entity_id\":\"................",target)
28 | target=str(target)
29 | target=re.sub(r'\D','',target)
30 |
31 | cookies = {
32 | 'c_user': user,
33 | 'xs': xs,
34 | }
35 |
36 | headers = {
37 | 'Content-Type': 'application/x-www-form-urlencoded, application/x-www-form-urlencoded',
38 | 'User-Agent': 'Mozilla/5.0',
39 | }
40 |
41 | data = {
42 | 'batch_name': 'MessengerGraphQLThreadFetcher',
43 | '__user': user,
44 | '__a': '1',
45 | 'fb_dtsg': dtsg,
46 | 'queries': '{"o0":{"doc_id":msg_fetch_doc_id_here,"query_params":{"id":'+target+',"message_limit":20000000000000000}}}'
47 | }
48 |
49 | response = requests.post('https://www.messenger.com/api/graphqlbatch/', headers=headers, cookies=cookies, data=data)
50 | out=response.text
51 | #sys.exit(out)
52 | clse=re.search('Please try closing and re-opening your browser window.', out)
53 | if clse!=None:
54 | sys.exit('Please check if the dtsg value is correct.\n If you continuously get this error, uncoment line 51 and run the script again and send me the output at prabesh01@pm.me')
55 | exp=re.search('Please log in to continue.', out)
56 | if exp!=None:
57 | sys.exit("Please check if cookies value is up-to-date.\n If you continuously get this error, uncoment line 51 and run the script again and send me the output at prabesh01@pm.me")
58 | sth=re.search('mid', out)
59 | if sth==None:
60 | sys.exit("Something went wrong, Please try again.\n If you continuously get this error, uncoment line 51 and run the script again and send me the output at prabesh01@pm.me")
61 |
62 | x=re.findall('mid\.\$.............................',out)
63 | x = list(dict.fromkeys(x))
64 | total=len(x)
65 |
66 | for count in reversed(range(total)):
67 | cookies = {
68 | 'c_user': user,
69 | 'xs': xs,
70 | }
71 |
72 | headers = {
73 | 'Content-Type': 'application/x-www-form-urlencoded',
74 | 'User-Agent': 'Mozilla/5.0',
75 | }
76 |
77 | data = {
78 | '__user': user,
79 | '__a': '1',
80 | 'fb_dtsg': dtsg,
81 | 'doc_id': doc,
82 | 'variables': '{"data":{"client_mutation_id":"2","actor_id":"100012709728678","action":"ADD_REACTION","message_id":"'+str(x[count])+'","reaction":"😇"}}'
83 | }
84 |
85 | response = requests.post('https://www.messenger.com/webgraphql/mutation/', headers=headers, cookies=cookies, data=data)
86 |
87 | print('-\n-\n-\n-\n-\n'+str(count)+'/'+str(total)+':\nDone')
88 |
89 | #for debug purpose:
90 | #print('-\n-\n-\n-\n-\n'+str(count)+'/'+str(total)+":\nRequest:\n"+str(response.request.headers)+'\n'+str(response.request.body)+"\n\nResponse:\n"+str(response.text))
91 | sys.exit('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCompleted Sucessfully!')
92 |
--------------------------------------------------------------------------------