forked from matiasinsaurralde/facebook-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb_chat_poc.rb
55 lines (37 loc) · 1.58 KB
/
fb_chat_poc.rb
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
#!/usr/bin/env ruby
# encoding: utf-8
# poc para usar el fb chat!
## curl -A "Mozilla Firefox" -s -b cookies.txt "https://m.facebook.com/messages/send/?icm=1&refid=12" -d "fb_dtsg=AQANMR10&body=test3&send=Responder&tids=mid.1361727138483:223bbd9ac2e4266071&wwwupp=V3&ids[100005347350787]=100005347350787"
## sin thread ids:
## curl -A "Mozilla Firefox" -s -b cookies.txt "https://m.facebook.com/messages/send/?icm=1&refid=12" -d "fb_dtsg=AQANMR10&body=test_sin_tids&send=Responder&wwwupp=V3&ids[100005347350787]=100005347350787"
require 'nokogiri'
$dest = 'someusername'
def get( url )
return `curl -A "Mozilla Firefox" -b cookies.txt -s "#{url}"`
end
def post( url, data )
composer_url = 'https://m.facebook.com/messages/send/?icm=1&refid=12'
data.merge!( { 'fb_dtsg' => 'AQANMR10',
'send' => 'Responder',
'wwwupp' => 'V3' } )
data_s = data.map { |k| "#{k[0]}=#{k[1]}" }.join('&')
`curl -A "Mozilla Firefox" -s -b cookies.txt "#{composer_url}" -d "#{data_s}"`
end
def get_thread_url( dest )
profile_body = get("https://m.facebook.com/#{dest}")
thread_url = nil
Nokogiri::HTML( profile_body ).css('a').each do |anchor|
href = anchor.attr('href').to_s
thread_url = href if href.include?( 'messages/thread' )
end
return thread_url
end
def send_msg( message, thread )
composer_url, tid = "https://m.facebook.com/messages/send/?icm=1&refid=12", thread.split('/')[3]
post( composer_url, { 'body' => message, "ids[#{tid}]" => tid } )
end
th = get_thread_url( $dest )
p th
exit
# th = "/messages/thread/xxxxxxxxxxx/?refid=17"
send_msg( 'asd', th )