通过电子邮件和WhatsApp向患者发送处方
这是一个Miscellaneous, Multimodal AI领域的自动化工作流,包含 8 个节点。主要使用 Code, Filter, WhatsApp, EmailSend, GoogleSheets 等节点。 通过Google Sheets自动化处方发送至电子邮件和WhatsApp
- •Google Sheets API 凭证
{
"id": "RiKOVQcW472o1Hfu",
"meta": {
"instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
"templateCredsSetupCompleted": true
},
"name": "通过电子邮件和 WhatsApp 向患者发送处方",
"tags": [],
"nodes": [
{
"id": "368d24da-9d79-4bf5-9c56-1f70bf74ab1e",
"name": "筛选新处方",
"type": "n8n-nodes-base.filter",
"position": [
-1240,
-120
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "1",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.prescription_status }}",
"rightValue": "new"
},
{
"id": "2",
"operator": {
"type": "string",
"operation": "isNotEmpty"
},
"leftValue": "={{ $json.patient_email }}",
"rightValue": ""
},
{
"id": "3",
"operator": {
"type": "string",
"operation": "isNotEmpty"
},
"leftValue": "={{ $json.patient_phone }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2
},
{
"id": "7ca917ec-330c-4f53-90ae-3fa7b7178200",
"name": "格式化处方数据",
"type": "n8n-nodes-base.code",
"position": [
-1020,
-120
],
"parameters": {
"jsCode": "// Format prescription data for email and WhatsApp\nconst items = $input.all();\n\nreturn items.map(item => {\n const data = item.json;\n \n // Format prescription text\n const prescriptionText = `\n🏥 PRESCRIPTION\n\nPatient: ${data.patient_name}\nDoctor: ${data.doctor_name}\nDate: ${data.prescription_date}\n\nPrescription Details:\n${data.prescription_details}\n\nDosage Instructions:\n${data.dosage_instructions}\n\nFollow-up Date: ${data.followup_date || 'Not specified'}\n\n⚠️ Important: Take medications as prescribed. Contact your doctor if you have any questions.\n `;\n \n // Format email HTML\n const emailHTML = `\n <div style=\"font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;\">\n <div style=\"background-color: #f8f9fa; padding: 20px; border-radius: 8px;\">\n <h2 style=\"color: #2c3e50; text-align: center;\">📋 Medical Prescription</h2>\n \n <div style=\"background-color: white; padding: 20px; border-radius: 6px; margin: 20px 0;\">\n <h3 style=\"color: #3498db; margin-top: 0;\">Patient Information</h3>\n <p><strong>Name:</strong> ${data.patient_name}</p>\n <p><strong>Doctor:</strong> ${data.doctor_name}</p>\n <p><strong>Date:</strong> ${data.prescription_date}</p>\n </div>\n \n <div style=\"background-color: white; padding: 20px; border-radius: 6px; margin: 20px 0;\">\n <h3 style=\"color: #27ae60; margin-top: 0;\">Prescription Details</h3>\n <p style=\"white-space: pre-line;\">${data.prescription_details}</p>\n </div>\n \n <div style=\"background-color: white; padding: 20px; border-radius: 6px; margin: 20px 0;\">\n <h3 style=\"color: #e74c3c; margin-top: 0;\">Dosage Instructions</h3>\n <p style=\"white-space: pre-line;\">${data.dosage_instructions}</p>\n </div>\n \n ${data.followup_date ? `\n <div style=\"background-color: white; padding: 20px; border-radius: 6px; margin: 20px 0;\">\n <h3 style=\"color: #f39c12; margin-top: 0;\">Follow-up</h3>\n <p><strong>Next Appointment:</strong> ${data.followup_date}</p>\n </div>\n ` : ''}\n \n <div style=\"background-color: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 6px; margin: 20px 0;\">\n <p style=\"margin: 0; color: #856404;\">⚠️ <strong>Important:</strong> Take medications exactly as prescribed. Contact your doctor if you experience any side effects or have questions.</p>\n </div>\n \n <div style=\"text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd;\">\n <p style=\"color: #7f8c8d; font-size: 12px;\">This prescription was sent automatically from our medical system.</p>\n </div>\n </div>\n </div>\n `;\n \n return {\n json: {\n ...data,\n prescriptionText,\n emailHTML,\n whatsappMessage: prescriptionText.replace(/🏥|📋|⚠️/g, ''), // Remove emojis for WhatsApp compatibility\n timestamp: new Date().toISOString()\n }\n };\n});"
},
"typeVersion": 2
},
{
"id": "73c4304b-ac16-4deb-aaae-d40c94c29de9",
"name": "发送 WhatsApp",
"type": "n8n-nodes-base.whatsApp",
"position": [
-800,
-20
],
"webhookId": "2ff35c14-14d6-485c-bf0f-8a460769b4dd",
"parameters": {
"textBody": "Hello [Patient Name], 👋 Your prescription from Dr. [Doctor Name] dated [Date] is ready. Please check the attached file for your medication details. 📞 For queries, contact us at [Contact Number]. [Clinic/Hospital Name]",
"operation": "send",
"phoneNumberId": "=+919988888888",
"additionalFields": {},
"recipientPhoneNumber": "=+91999999999999"
},
"credentials": {
"whatsAppApi": {
"id": "b0PxTDPdWzznWnfG",
"name": "WhatsApp-test "
}
},
"typeVersion": 1
},
{
"id": "cc159a2b-d6c2-414d-b3bc-05f4d0a16b29",
"name": "记录通知",
"type": "n8n-nodes-base.googleSheets",
"position": [
-580,
-120
],
"parameters": {
"columns": {
"value": {
"timestamp": "={{ $json.timestamp }}",
"doctor_name": "={{ $json.doctor_name }}",
"email_status": "={{ $('Send email').item.json.success ? 'sent' : 'failed' }}",
"patient_name": "={{ $json.patient_name }}",
"patient_email": "={{ $json.patient_email }}",
"patient_phone": "={{ $json.patient_phone }}",
"prescription_id": "={{ $json.prescription_id }}",
"whatsapp_status": "={{ $('Send WhatsApp').item.json.success ? 'sent' : 'failed' }}",
"notification_type": "prescription_sent"
},
"schema": [
{
"id": "timestamp",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "timestamp",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "patient_name",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "patient_name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "patient_email",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "patient_email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "patient_phone",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "patient_phone",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "doctor_name",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "doctor_name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "prescription_id",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "prescription_id",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "email_status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "email_status",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "whatsapp_status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "whatsapp_status",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "notification_type",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "notification_type",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"patient_name"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "appendOrUpdate",
"sheetName": "Notification_Log",
"documentId": {
"__rl": true,
"mode": "url",
"value": "=YOUR_GOOGLE_SHEET"
},
"authentication": "serviceAccount"
},
"credentials": {
"googleApi": {
"id": "ScSS2KxGQULuPtdy",
"name": "Google Sheets- test"
}
},
"typeVersion": 4
},
{
"id": "0c9e09cb-1d80-4f09-abfd-4d3d712833ef",
"name": "更新处方状态",
"type": "n8n-nodes-base.googleSheets",
"position": [
-360,
-120
],
"parameters": {
"columns": {
"value": {
"prescription_status": "sent"
},
"schema": [
{
"id": "prescription_id",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "prescription_id",
"defaultMatch": true,
"canBeUsedToMatch": true
},
{
"id": "prescription_status",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "prescription_status",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"prescription_id"
]
},
"options": {},
"operation": "update",
"sheetName": "Prescriptions",
"documentId": {
"__rl": true,
"mode": "url",
"value": "=YOUR_GOOGLE_SHEET"
},
"authentication": "serviceAccount"
},
"credentials": {
"googleApi": {
"id": "ScSS2KxGQULuPtdy",
"name": "Google Sheets- test"
}
},
"typeVersion": 4
},
{
"id": "5c2bf898-b7a2-43c9-a90d-e852fecf829e",
"name": "Google Sheets 触发器",
"type": "n8n-nodes-base.googleSheetsTrigger",
"position": [
-1460,
-120
],
"parameters": {
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"sheetName": {
"__rl": true,
"mode": "id",
"value": "=cfrt5tgbhu8iujnjio90"
},
"documentId": {
"__rl": true,
"mode": "id",
"value": "=ojnbgt56ybb"
}
},
"credentials": {
"googleSheetsTriggerOAuth2Api": {
"id": "BoDTTv5L67GVL3Fi",
"name": "Google Sheets - test"
}
},
"typeVersion": 1
},
{
"id": "530efe83-c80e-4b1e-8121-c508907cecd1",
"name": "发送电子邮件",
"type": "n8n-nodes-base.emailSend",
"position": [
-800,
-220
],
"webhookId": "4316a3ab-1861-43cb-9b7a-446b0938186e",
"parameters": {
"text": "Dear [Patient Name],\n\nPlease find attached your prescription from Dr. [Doctor Name] dated [Date].\nIf you have any questions about your medication, kindly contact our clinic.\n\nAttachment: Prescription PDF/Image\n\nBest regards,\n[Clinic/Hospital Name]\n[Contact Number] | [Email Address]",
"options": {
"appendAttribution": false,
"allowUnauthorizedCerts": false
},
"subject": "Your Prescription from [Doctor/Hospital Name]",
"toEmail": "={{ $json.patient_email }}",
"fromEmail": "noreply@yourhospital.com"
},
"credentials": {
"smtp": {
"id": "G1kyF8cSWTZ4vouN",
"name": "SMTP -test"
}
},
"typeVersion": 2
},
{
"id": "41b633a7-3641-4816-8b13-eb26a3d37686",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1580,
-480
],
"parameters": {
"color": 3,
"width": 660,
"height": 260,
"content": "## 🌟 包含功能"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "62ea4e96-2323-44a0-8a1c-9726039672be",
"connections": {
"Send email": {
"main": [
[
{
"node": "Log Notification",
"type": "main",
"index": 0
}
]
]
},
"Send WhatsApp": {
"main": [
[
{
"node": "Log Notification",
"type": "main",
"index": 0
}
]
]
},
"Log Notification": {
"main": [
[
{
"node": "Update Prescription Status",
"type": "main",
"index": 0
}
]
]
},
"Google Sheets Trigger": {
"main": [
[
{
"node": "Filter New Prescriptions",
"type": "main",
"index": 0
}
]
]
},
"Filter New Prescriptions": {
"main": [
[
{
"node": "Format Prescription Data",
"type": "main",
"index": 0
}
]
]
},
"Format Prescription Data": {
"main": [
[
{
"node": "Send email",
"type": "main",
"index": 0
},
{
"node": "Send WhatsApp",
"type": "main",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 杂项, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Oneclick AI Squad
@oneclick-aiThe AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.
分享此工作流