-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb2twilio.py
31 lines (25 loc) · 1.02 KB
/
fb2twilio.py
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
import creds
import threading
from fbchat import Client
from fbchat.models import *
from twilio.rest import Client as TwilioClient
def forwardMsg(msg):
tclient.messages.create(
to=creds.twilio['phone'],
from_=creds.twilio['twilio_phone'],
body=str(msg)
)
class CustomClient(Client):
def onMessage(self, mid, author_id, message_object, thread_id, thread_type, ts, metadata, msg, **kwargs):
author = self.fetchUserInfo(author_id).values()[0]
# print 'new msg from ({:s}):'.format(author.name), msg['delta']['body']
thr = threading.Thread(target=forwardMsg, args=['\n{:s}: '.format(author.name)+ msg['delta']['body']])
thr.start()
# if __name__ == '__main__':
# tclient = TwilioClient(creds.twilio['sid'], creds.twilio['auth'])
# fclient = CustomClient(creds.fb['email'], creds.fb['pwd'])
# fclient.listen()
tclient = TwilioClient(creds.twilio['sid'], creds.twilio['auth'])
fclient = CustomClient(creds.fb['email'], creds.fb['pwd'])
def run():
fclient.listen()