Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions FuncNotify/wechat_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from wechatpy import WeChatClient
from wechatpy.exceptions import WeChatClientException

class WeChatMethod:
def __init__(self, app_id, app_secret):
"""
Initialize the WeChatMethod class with WeChat AppID and AppSecret.

:param app_id: WeChat AppID
:param app_secret: WeChat AppSecret
"""
self.client = WeChatClient(app_id, app_secret)

def send_notification(self, openid, message):
"""
Send a WeChat notification to a user.

:param openid: The recipient's WeChat OpenID
:param message: The message to send
"""
try:
self.client.message.send_text(openid, message)
print(f"WeChat message sent to {openid}")
except WeChatClientException as e:
print(f"Failed to send WeChat message: {e}")

# Example usage
if __name__ == "__main__":
# Replace with your WeChat credentials
app_id = "your_app_id"
app_secret = "your_app_secret"

wechat = WeChatMethod(app_id, app_secret)
wechat.send_notification("user_openid", "Hello from FuncNotify via WeChat!")
42 changes: 42 additions & 0 deletions FuncNotify/whatsapp_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# whatsapp_method.py

from twilio.rest import Client

class WhatsAppMethod:
def __init__(self, account_sid, auth_token, from_whatsapp_number):
"""
Initialize the WhatsAppMethod class with Twilio credentials and sender number.

:param account_sid: Twilio Account SID
:param auth_token: Twilio Auth Token
:param from_whatsapp_number: Twilio WhatsApp-approved sender number
"""
self.client = Client(account_sid, auth_token)
self.from_whatsapp_number = from_whatsapp_number

def send_notification(self, to_number, message):
"""
Send a WhatsApp notification to the recipient.

:param to_number: Recipient's WhatsApp number (in international format)
:param message: Message to send
"""
try:
self.client.messages.create(
from_=self.from_whatsapp_number,
to=f"whatsapp:{to_number}",
body=message,
)
print(f"WhatsApp message sent to {to_number}")
except Exception as e:
print(f"Failed to send WhatsApp message: {e}")

# Example usage
if __name__ == "__main__":
# Replace with your Twilio credentials and numbers
account_sid = "your_account_sid"
auth_token = "your_auth_token"
from_whatsapp_number = "whatsapp:+14155238886"

whatsapp = WhatsAppMethod(account_sid, auth_token, from_whatsapp_number)
whatsapp.send_notification("+1234567890", "Hello from FuncNotify via WhatsApp!")