Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from vonage import Vonage, Auth
- from vonage_sms import SmsMessage
- def main():
- # 1. Use the new Vonage and Auth classes for initialization
- client = Vonage(Auth(api_key="476f27f2", api_secret="..."))
- # 2. Use the SmsMessage object instead of a dictionary
- # Note: Use 'from_' because 'from' is a reserved keyword in Python
- message = SmsMessage(
- to="40750760880",
- from_="Vonage APIs",
- text="A text message sent using the Vonage SMS API"
- )
- # 3. Send the message
- response = client.sms.send(message)
- # 4. Access response data (it returns an object, not a dictionary now)
- if response.messages[0].status == "0":
- print("Message sent successfully.")
- else:
- print(f"Message failed with error: {response.messages[0].error_text}")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment