Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 4bf4490

Browse files
author
Andrew Stroup
committed
add Twilio functionality
1 parent 3b09db5 commit 4bf4490

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Clone this repo and update `lambda_function.py`.
9292
# lambda_function.py
9393
account_sid = "account_sid" # Twilio account SID
9494
auth_token = "auth_token" # Twilio auth token
95+
phone_number = "phone_number" # Twilio phone number
9596
dynamodb = boto3.resource('dynamodb', '_region') # AWS region set in Pre-Requisites
9697
table_users = dynamodb.Table('table_name') # name of DyanmoDB created in Pre-Requisites
9798
```

lambda_function.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
account_sid = "account_sid"
2424
auth_token = "auth_token"
2525
client = TwilioRestClient(account_sid, auth_token)
26+
phone_number = "phone_number" # +10000000000
2627

2728
# create an S3 & Dynamo session
2829
s3 = boto3.resource('s3')
@@ -40,6 +41,10 @@ def sample_filter(im):
4041
filter_image = ImageOps.colorize(ImageOps.grayscale(im), black, white)
4142
return filter_image
4243

44+
def send_message(event, response):
45+
client.messages.create(to=event['fromNumber'], from_=phone_number,
46+
body=response)
47+
4348
def lambda_handler(event, context):
4449

4550
message = event['body']
@@ -53,11 +58,15 @@ def lambda_handler(event, context):
5358
# a new user
5459
if response_dynamo['Count'] == 0:
5560
if len(message) == 0:
56-
return "Please send us an SMS with your name first!"
61+
response = "Please send us an SMS with your name first!"
62+
send_message(event, response)
63+
return response
5764
else:
5865
name = message.split(" ")
5966
table_users.put_item(Item={'fromNumber': from_number, 'name': name[0]})
60-
return "We've added {0} to the system! Now send us a selfie! ".format(name[0])
67+
response = "We've added {0} to the system! Now send us a selfie! ".format(name[0])
68+
send_message(event, response)
69+
return response
6170
else:
6271
name = response_dynamo['Items'][0]['name']
6372

@@ -86,6 +95,8 @@ def lambda_handler(event, context):
8695

8796
s3.Bucket(bucket).put_object(Key=key, Body=im_data, ACL='public-read', ContentType='image/png', Metadata=m_data)
8897
else:
89-
twilio_resp = 'No image found'
90-
98+
99+
twilio_resp = "No image found, try sending a selfie!"
100+
101+
send_message(event, twilio_resp)
91102
return twilio_resp

0 commit comments

Comments
 (0)