[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-2a4c35d9-ea83-432f-8d9c-cbfc17b5d40d":3,"$fK4gHS-nGhi8ltE233n7ki3x5c75fy3-Hghhq_V4iuCA":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"2a4c35d9-ea83-432f-8d9c-cbfc17b5d40d","azure-communication-sms-java","使用Azure通信服务SMS Java SDK发送短信消息。在实现短信通知、警报、OTP投递、批量消息或投递报告时使用。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-communication-sms-java\ndescription: \"Send SMS messages with Azure Communication Services SMS Java SDK. Use when implementing SMS notifications, alerts, OTP delivery, bulk messaging, or delivery reports.\"\nrisk: safe\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Communication SMS (Java)\n\nSend SMS messages to single or multiple recipients with delivery reporting.\n\n## Installation\n\n```xml\n\u003Cdependency>\n    \u003CgroupId>com.azure\u003C\u002FgroupId>\n    \u003CartifactId>azure-communication-sms\u003C\u002FartifactId>\n    \u003Cversion>1.2.0\u003C\u002Fversion>\n\u003C\u002Fdependency>\n```\n\n## Client Creation\n\n```java\nimport com.azure.communication.sms.SmsClient;\nimport com.azure.communication.sms.SmsClientBuilder;\nimport com.azure.identity.DefaultAzureCredentialBuilder;\n\n\u002F\u002F With DefaultAzureCredential (recommended)\nSmsClient smsClient = new SmsClientBuilder()\n    .endpoint(\"https:\u002F\u002F\u003Cresource>.communication.azure.com\")\n    .credential(new DefaultAzureCredentialBuilder().build())\n    .buildClient();\n\n\u002F\u002F With connection string\nSmsClient smsClient = new SmsClientBuilder()\n    .connectionString(\"\u003Cconnection-string>\")\n    .buildClient();\n\n\u002F\u002F With AzureKeyCredential\nimport com.azure.core.credential.AzureKeyCredential;\n\nSmsClient smsClient = new SmsClientBuilder()\n    .endpoint(\"https:\u002F\u002F\u003Cresource>.communication.azure.com\")\n    .credential(new AzureKeyCredential(\"\u003Caccess-key>\"))\n    .buildClient();\n\n\u002F\u002F Async client\nSmsAsyncClient smsAsyncClient = new SmsClientBuilder()\n    .connectionString(\"\u003Cconnection-string>\")\n    .buildAsyncClient();\n```\n\n## Send SMS to Single Recipient\n\n```java\nimport com.azure.communication.sms.models.SmsSendResult;\n\n\u002F\u002F Simple send\nSmsSendResult result = smsClient.send(\n    \"+14255550100\",      \u002F\u002F From (your ACS phone number)\n    \"+14255551234\",      \u002F\u002F To\n    \"Your verification code is 123456\");\n\nSystem.out.println(\"Message ID: \" + result.getMessageId());\nSystem.out.println(\"To: \" + result.getTo());\nSystem.out.println(\"Success: \" + result.isSuccessful());\n\nif (!result.isSuccessful()) {\n    System.out.println(\"Error: \" + result.getErrorMessage());\n    System.out.println(\"Status: \" + result.getHttpStatusCode());\n}\n```\n\n## Send SMS to Multiple Recipients\n\n```java\nimport com.azure.communication.sms.models.SmsSendOptions;\nimport java.util.Arrays;\nimport java.util.List;\n\nList\u003CString> recipients = Arrays.asList(\n    \"+14255551111\",\n    \"+14255552222\",\n    \"+14255553333\"\n);\n\n\u002F\u002F With options\nSmsSendOptions options = new SmsSendOptions()\n    .setDeliveryReportEnabled(true)\n    .setTag(\"marketing-campaign-001\");\n\nIterable\u003CSmsSendResult> results = smsClient.sendWithResponse(\n    \"+14255550100\",      \u002F\u002F From\n    recipients,          \u002F\u002F To list\n    \"Flash sale! 50% off today only.\",\n    options,\n    Context.NONE\n).getValue();\n\nfor (SmsSendResult result : results) {\n    if (result.isSuccessful()) {\n        System.out.println(\"Sent to \" + result.getTo() + \": \" + result.getMessageId());\n    } else {\n        System.out.println(\"Failed to \" + result.getTo() + \": \" + result.getErrorMessage());\n    }\n}\n```\n\n## Send Options\n\n```java\nSmsSendOptions options = new SmsSendOptions();\n\n\u002F\u002F Enable delivery reports (sent via Event Grid)\noptions.setDeliveryReportEnabled(true);\n\n\u002F\u002F Add custom tag for tracking\noptions.setTag(\"order-confirmation-12345\");\n```\n\n## Response Handling\n\n```java\nimport com.azure.core.http.rest.Response;\n\nResponse\u003CIterable\u003CSmsSendResult>> response = smsClient.sendWithResponse(\n    \"+14255550100\",\n    Arrays.asList(\"+14255551234\"),\n    \"Hello!\",\n    new SmsSendOptions().setDeliveryReportEnabled(true),\n    Context.NONE\n);\n\n\u002F\u002F Check HTTP response\nSystem.out.println(\"Status code: \" + response.getStatusCode());\nSystem.out.println(\"Headers: \" + response.getHeaders());\n\n\u002F\u002F Process results\nfor (SmsSendResult result : response.getValue()) {\n    System.out.println(\"Message ID: \" + result.getMessageId());\n    System.out.println(\"Successful: \" + result.isSuccessful());\n    \n    if (!result.isSuccessful()) {\n        System.out.println(\"HTTP Status: \" + result.getHttpStatusCode());\n        System.out.println(\"Error: \" + result.getErrorMessage());\n    }\n}\n```\n\n## Async Operations\n\n```java\nimport reactor.core.publisher.Mono;\n\nSmsAsyncClient asyncClient = new SmsClientBuilder()\n    .connectionString(\"\u003Cconnection-string>\")\n    .buildAsyncClient();\n\n\u002F\u002F Send single message\nasyncClient.send(\"+14255550100\", \"+14255551234\", \"Async message!\")\n    .subscribe(\n        result -> System.out.println(\"Sent: \" + result.getMessageId()),\n        error -> System.out.println(\"Error: \" + error.getMessage())\n    );\n\n\u002F\u002F Send to multiple with options\nSmsSendOptions options = new SmsSendOptions()\n    .setDeliveryReportEnabled(true);\n\nasyncClient.sendWithResponse(\n    \"+14255550100\",\n    Arrays.asList(\"+14255551111\", \"+14255552222\"),\n    \"Bulk async message\",\n    options)\n    .subscribe(response -> {\n        for (SmsSendResult result : response.getValue()) {\n            System.out.println(\"Result: \" + result.getTo() + \" - \" + result.isSuccessful());\n        }\n    });\n```\n\n## Error Handling\n\n```java\nimport com.azure.core.exception.HttpResponseException;\n\ntry {\n    SmsSendResult result = smsClient.send(\n        \"+14255550100\",\n        \"+14255551234\",\n        \"Test message\"\n    );\n    \n    \u002F\u002F Individual message errors don't throw exceptions\n    if (!result.isSuccessful()) {\n        handleMessageError(result);\n    }\n    \n} catch (HttpResponseException e) {\n    \u002F\u002F Request-level failures (auth, network, etc.)\n    System.out.println(\"Request failed: \" + e.getMessage());\n    System.out.println(\"Status: \" + e.getResponse().getStatusCode());\n} catch (RuntimeException e) {\n    System.out.println(\"Unexpected error: \" + e.getMessage());\n}\n\nprivate void handleMessageError(SmsSendResult result) {\n    int status = result.getHttpStatusCode();\n    String error = result.getErrorMessage();\n    \n    if (status == 400) {\n        System.out.println(\"Invalid phone number: \" + result.getTo());\n    } else if (status == 429) {\n        System.out.println(\"Rate limited - retry later\");\n    } else {\n        System.out.println(\"Error \" + status + \": \" + error);\n    }\n}\n```\n\n## Delivery Reports\n\nDelivery reports are sent via Azure Event Grid. Configure an Event Grid subscription for your ACS resource.\n\n```java\n\u002F\u002F Event Grid webhook handler (in your endpoint)\npublic void handleDeliveryReport(String eventJson) {\n    \u002F\u002F Parse Event Grid event\n    \u002F\u002F Event type: Microsoft.Communication.SMSDeliveryReportReceived\n    \n    \u002F\u002F Event data contains:\n    \u002F\u002F - messageId: correlates to SmsSendResult.getMessageId()\n    \u002F\u002F - from: sender number\n    \u002F\u002F - to: recipient number\n    \u002F\u002F - deliveryStatus: \"Delivered\", \"Failed\", etc.\n    \u002F\u002F - deliveryStatusDetails: detailed status\n    \u002F\u002F - receivedTimestamp: when status was received\n    \u002F\u002F - tag: your custom tag from SmsSendOptions\n}\n```\n\n## SmsSendResult Properties\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `getMessageId()` | String | Unique message identifier |\n| `getTo()` | String | Recipient phone number |\n| `isSuccessful()` | boolean | Whether send succeeded |\n| `getHttpStatusCode()` | int | HTTP status for this recipient |\n| `getErrorMessage()` | String | Error details if failed |\n| `getRepeatabilityResult()` | RepeatabilityResult | Idempotency result |\n\n## Environment Variables\n\n```bash\nAZURE_COMMUNICATION_ENDPOINT=https:\u002F\u002F\u003Cresource>.communication.azure.com\nAZURE_COMMUNICATION_CONNECTION_STRING=endpoint=https:\u002F\u002F...;accesskey=...\nSMS_FROM_NUMBER=+14255550100\n```\n\n## Best Practices\n\n1. **Phone Number Format** - Use E.164 format: `+[country code][number]`\n2. **Delivery Reports** - Enable for critical messages (OTP, alerts)\n3. **Tagging** - Use tags to correlate messages with business context\n4. **Error Handling** - Check `isSuccessful()` for each recipient individually\n5. **Rate Limiting** - Implement retry with backoff for 429 responses\n6. **Bulk Sending** - Use batch send for multiple recipients (more efficient)\n\n## Trigger Phrases\n\n- \"send SMS Java\", \"text message Java\"\n- \"SMS notification\", \"OTP SMS\", \"bulk SMS\"\n- \"delivery report SMS\", \"Azure Communication Services SMS\"\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,150,1555,"2026-05-16 13:06:00",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"8dd48266-d132-4096-a672-f214dab181ff","1.0.0","azure-communication-sms-java.zip",2849,"uploads\u002Fskills\u002F2a4c35d9-ea83-432f-8d9c-cbfc17b5d40d\u002Fazure-communication-sms-java.zip","3eb5b0d45a658a63c456307bd23aecb0f8fc6f89ec050edaf3dcbcf1ced468d8","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":8509}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]