Spaces:
Running
Running
Commit
·
b2f9359
1
Parent(s):
5458d13
send message by whatsapp
Browse files- app.py +24 -9
- requirements.txt +1 -0
- sendMailtest.py +49 -0
app.py
CHANGED
|
@@ -13,12 +13,19 @@ import numpy as np
|
|
| 13 |
import smtplib
|
| 14 |
import os
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
from tools.final_answer import FinalAnswerTool
|
| 17 |
from tools.visit_webpage import VisitWebpageTool
|
| 18 |
from tools.web_search import DuckDuckGoSearchTool
|
| 19 |
from typing import Optional, Tuple
|
| 20 |
MY_EMAIL="[email protected]"
|
| 21 |
MY_PASSWORD = os.getenv('gmail')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 23 |
model = HfApiModel(
|
| 24 |
max_tokens=2096,
|
|
@@ -52,17 +59,25 @@ def send_message_tool(query: str) -> str:
|
|
| 52 |
"""
|
| 53 |
try:
|
| 54 |
# Create the email message
|
| 55 |
-
print("sending
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
return f"Message sent to tianqing successfully!"
|
| 64 |
except Exception as e:
|
| 65 |
-
return f"Failed to send
|
| 66 |
|
| 67 |
|
| 68 |
@tool
|
|
@@ -124,7 +139,7 @@ def send_message(user_input):
|
|
| 124 |
try:
|
| 125 |
# Create the email message
|
| 126 |
print("sending mail")
|
| 127 |
-
|
| 128 |
with smtplib.SMTP("smtp.gmail.com",8888) as connection:
|
| 129 |
connection.starttls()
|
| 130 |
connection.login(MY_EMAIL, MY_PASSWORD)
|
|
|
|
| 13 |
import smtplib
|
| 14 |
import os
|
| 15 |
|
| 16 |
+
from twilio.http.http_client import TwilioHttpClient
|
| 17 |
+
from twilio.rest import Client
|
| 18 |
+
|
| 19 |
from tools.final_answer import FinalAnswerTool
|
| 20 |
from tools.visit_webpage import VisitWebpageTool
|
| 21 |
from tools.web_search import DuckDuckGoSearchTool
|
| 22 |
from typing import Optional, Tuple
|
| 23 |
MY_EMAIL="[email protected]"
|
| 24 |
MY_PASSWORD = os.getenv('gmail')
|
| 25 |
+
PHONE = os.getenv('phone')
|
| 26 |
+
account_sid = os.getenv('twillo_sid')
|
| 27 |
+
auth_token = os.getenv('twillo_token')
|
| 28 |
+
|
| 29 |
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 30 |
model = HfApiModel(
|
| 31 |
max_tokens=2096,
|
|
|
|
| 59 |
"""
|
| 60 |
try:
|
| 61 |
# Create the email message
|
| 62 |
+
print("sending message")
|
| 63 |
+
proxy_client = TwilioHttpClient()
|
| 64 |
+
proxy_client.session.proxies = {'https': os.environ['https_proxy']}
|
| 65 |
+
client = Client(account_sid, auth_token)
|
| 66 |
+
message = client.messages.create(
|
| 67 |
+
from_='whatsapp:+14155238886',
|
| 68 |
+
body ='f{query}',
|
| 69 |
+
to=f'whatsapp:{PHONE}'
|
| 70 |
+
)
|
| 71 |
+
# with smtplib.SMTP("smtp.gmail.com") as connection:
|
| 72 |
+
# connection.starttls()
|
| 73 |
+
# connection.login(MY_EMAIL, MY_PASSWORD)
|
| 74 |
+
# connection.sendmail(from_addr=MY_EMAIL,
|
| 75 |
+
# to_addrs=MY_EMAIL,
|
| 76 |
+
# msg=f"Subject: message from chatbot \n\n{query}")
|
| 77 |
|
| 78 |
return f"Message sent to tianqing successfully!"
|
| 79 |
except Exception as e:
|
| 80 |
+
return f"Failed to send message: {e}"
|
| 81 |
|
| 82 |
|
| 83 |
@tool
|
|
|
|
| 139 |
try:
|
| 140 |
# Create the email message
|
| 141 |
print("sending mail")
|
| 142 |
+
|
| 143 |
with smtplib.SMTP("smtp.gmail.com",8888) as connection:
|
| 144 |
connection.starttls()
|
| 145 |
connection.login(MY_EMAIL, MY_PASSWORD)
|
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
twilio
|
sendMailtest.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
from email.message import EmailMessage
|
| 3 |
+
|
| 4 |
+
import google.auth
|
| 5 |
+
from googleapiclient.discovery import build
|
| 6 |
+
from googleapiclient.errors import HttpError
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def gmail_send_message():
|
| 10 |
+
"""Create and send an email message
|
| 11 |
+
Print the returned message id
|
| 12 |
+
Returns: Message object, including message id
|
| 13 |
+
|
| 14 |
+
Load pre-authorized user credentials from the environment.
|
| 15 |
+
TODO(developer) - See https://developers.google.com/identity
|
| 16 |
+
for guides on implementing OAuth2 for the application.
|
| 17 |
+
"""
|
| 18 |
+
creds, _ = google.auth.default()
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
service = build("gmail", "v1", credentials=creds)
|
| 22 |
+
message = EmailMessage()
|
| 23 |
+
|
| 24 |
+
message.set_content("This is automated draft mail")
|
| 25 |
+
|
| 26 |
+
message["To"] = "[email protected]"
|
| 27 |
+
message["From"] = "[email protected]"
|
| 28 |
+
message["Subject"] = "Automated draft"
|
| 29 |
+
|
| 30 |
+
# encoded message
|
| 31 |
+
encoded_message = base64.urlsafe_b64encode(message.as_bytes()).decode()
|
| 32 |
+
|
| 33 |
+
create_message = {"raw": encoded_message}
|
| 34 |
+
# pylint: disable=E1101
|
| 35 |
+
send_message = (
|
| 36 |
+
service.users()
|
| 37 |
+
.messages()
|
| 38 |
+
.send(userId="me", body=create_message)
|
| 39 |
+
.execute()
|
| 40 |
+
)
|
| 41 |
+
print(f'Message Id: {send_message["id"]}')
|
| 42 |
+
except HttpError as error:
|
| 43 |
+
print(f"An error occurred: {error}")
|
| 44 |
+
send_message = None
|
| 45 |
+
return send_message
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
gmail_send_message()
|