-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscriber.py
More file actions
38 lines (29 loc) · 987 Bytes
/
Copy pathsubscriber.py
File metadata and controls
38 lines (29 loc) · 987 Bytes
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
import os
from dotenv import load_dotenv
from google.cloud import pubsub_v1
from concurrent.futures import TimeoutError
from twilio.rest import Client
load_dotenv()
credentials_path = 'twilioapi-privatekey.json'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
account_sid = os.getenv('account_sid')
auth_token = os.getenv('auth_token')
client = Client(account_sid, auth_token)
timeout = 5.0
subscriber = pubsub_v1.SubscriberClient()
subscription_path = 'projects/stalwart-realm-339201/subscriptions/fraudulent-sub'
message = client.messages.create(
from_='+18447813048',
body='test',
to='+16102481063'
)
def callback(message):
print(message.sid)
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback)
print(f'Listening for messages on {subscription_path}')
with subscriber:
try:
streaming_pull_future.result()
except TimeoutError:
streaming_pull_future.cancel()
streaming_pull_future.result()