21
loading...
This website collects cookies to deliver better user experience
pip install tuya-iot-py-sdk
TuyaOpenAPI
from Tuya Connecter that we installed before.from tuya_connector import (
TuyaOpenAPI
)
ACCESS_ID = "*************123"
ACCESS_KEY = "*************56565"
API_ENDPOINT = "https://openapi.tuyain.com"
MQ_ENDPOINT = "wss://mqe.tuyacn.com:8285/"
ACCESS_ID
and ACCESS_KEY
are on your Tuya project.API_ENDPOINT
is set to your location.openapi = TuyaOpenAPI(API_ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect()
sent = openapi.post("/v1.0/iot-03/messages/mails/actions/push", dict({ "to_address": "[email protected]",
"template_id": "MAIL_1624531323",
"reply_to_address": "[email protected]"}))
POST
: Requires the server to perform specified operations.GET
: Requests the server to return specified resources.PUT
: Requests the server to update specified resources.DELETE
: Requires the server to delete specified resources.template_id
is the ID of an email template. You can make them yourself(I will show you later) or use a public one. Tuya gives 2 public default templates,
MAIL_1624531323
MAIL_1624531338
reply_to_address
means the address that the user will send replies to.
{'result': {'send_status': True}, 'success': True, 't': 1634215134788}
temp = openapi.post("/v1.0/iot-03/msg-templates/mails",dict ( {"name": "Here's your code!",
"title": "Hello!",
"sender_name": "Booba",
"content": "Hey! You're so pretty btw",
"type": 2,
"remark": "Isn't it?"}
))
name
stands for the template name. And the title
is the template title. sender_name
is the sender name with 1 to 30 characters. For example, if you set the sender to Buddy, and the sender’s email address to [email protected]. The receiver will see the sender’s address as “Buddy” [email protected].content
is the content, which means the HTML format and Text!type
stands for email type. It will handle whether the email should be in the 'Primary' tab or 'Promotions'. There are 3 valid email types,
0
: verification code. 1
: email notification.2
: promotional email.remark
is remarks of the application for the email template. Describe your application scenario here!{'result': {'template_id': 'MAIL_0769019106'}, 'success': True, 't': 1634216025543}
0
: Verification code.1
: Notification
-2
: Promotional messagesresult = openapi.post("/v1.0/iot-03/msg-templates/sms", dict({ "name": "The template of the message verification code",
"content": "You are registering with your phone number. The verification code is: ${code}, valid for 5 minutes.",
"type": 0}))
print(result)
name
is the name of your template.content
stands for the message content.type
is for the type of the message— verification code, notification, or promotional.{'result': {'template_id': 'SMS_6195054734'}, 'success': True, 't': 1635956558065}
openapi.get("/v1.0/iot-03/msg-templates/sms/{template_id}")
send = openapi.post("/v1.0/iot-03/messages/sms/actions/push", dict({ "country_code": "94",
"phone": "945555555",
"template_id": "SMS_3746838509"}))
print(send)
country_code
is for your country code and don't use the +
mark in that.phone
stands for the phone number(s) that you need to send messages. The same rule, no symbols.template_id
is the Template ID that you made before, which has been approved.{'result': 'send_status': True, 'success': True, 't': 1634216025543}