Python script utilizing the Twilio SMS API and many others to create a virtual assistant that will set reminders, tell you the weather, utilize openai's technology, and much more!
After cloning the project establish a .env file with these credientials:
canvasAPIKey = XXXXXXXXXXXXXXX
canvasUserNumber = XXXXXXXXXXXXXXX
numberFrom = XXXXXXXXXXXXXXX
numberTo = XXXXXXXXXXXXXXX
openaiApiKey = XXXXXXXXXXXXXXX
twilioAccountSid = XXXXXXXXXXXXXXX
twilioAuthToken = XXXXXXXXXXXXXXX
This is what powers the whole application. Without Twilio there would be no phone number to text or SMS messages to send. To make an account go here. Once completed you can go to your console and you will see your Account SID, Authentication Token, and Twilio Phone Number.
Go to XXXXX.instructure.com > Account > Settings > Generate New Token
The generate new Token Button will look like this
After you click New Access Token you will be prompted to create an expiration date and specify the purpose. Specifying the purpose has no effect on the program it is just for organizational purposes if you have multiple access tokens. For the expiration date you can create one at your discretion, I did not create an expiration date for less maintence, but if you are concerned for the security of the program go ahead and create one.
Go to this link and create an account. Once you have made an account, go to the upper right hand corner and click "View API Keys".
Once clicked you simply press "Create new secret key". Make sure to note it down some place because once you click off the pop up you will no longer have access to the key and will have to make a new one.
Go to this link and create an account. Once you have made an account, again go to the upper right hand corner and click "My API keys".
Then give your key a name (again the name of the key doesn't effect its functionality) and press generate.
This program is based upon a flask application. As such, it must be hosted somewhere either locally or externally. I recommend hosting your code externally as you wouldn't have to burdern your device with running the application 24/7. To host on AWS (as I did) watch this tutorial by Caleb Curry!
If you want to host your code locally then follow this tutorial by the Twilio team about Ngrok!
Once you are through the process of hosting your code then you will be left with a url. To finally connect your code to Twilio head over to this Twilio's Website and click Phone Numbers > Manage > Active Numbers and click on your number in the console (it should be in blue text). Then scroll all the way down and paste your link where I have in this picture.
Make sure
- The end of your url is appended with '/sms'
- You are configuring the "A message comes in" webhook
- The webhook is set to HTTP POST
- "hi" --> "Hey there!"
- "gpt: " --> Whatever is put after the colon will be put through ChatGPT using the OpenAI's API and the user will get the appropriate response
- "weather" --> Will output the current temperature, high and low of the day, and what time the sun will set
- "picture: " --> Whatever is put after the colon will be put through DALLE 2 using OpenAI's API and the user will get the appropriate response
- "balance" --> If using Twilio's free account it will output how much money is left in the account