### Install serverchan-sdk using pip Source: https://github.com/easychen/serverchan-sdk/blob/master/pip/README.md This command installs the serverchan-sdk package using pip, the Python package installer. Ensure you have pip installed and accessible in your environment. ```bash pip install serverchan-sdk ``` -------------------------------- ### Install requests library for ServerChan-SDK Source: https://github.com/easychen/serverchan-sdk/blob/master/pip/README.md This command installs the 'requests' library, which is a required dependency for the serverchan-sdk. The 'requests' library is used for making HTTP requests to the ServerChan API. ```bash pip install requests ``` -------------------------------- ### Golang SDK: Send Notification Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This example demonstrates sending a notification using the Golang SDK for Server酱. It requires importing the `serverchan-sdk-golang` package and uses the `ScSend` function. The function takes the sendkey, title, desp, and an optional options parameter (passed as nil in this example). Error handling is included. ```go package main import ( "fmt" "github.com/easychen/serverchan-sdk-golang" ) func main() { sendkey := "your-sendkey" title := "Test Message" desp := "This is a test message" resp, err := serverchan_sdk.ScSend(sendkey, title, desp, nil) if err != nil { fmt.Println("Error:", err) } else { fmt.Println("Response:", resp) } } ``` -------------------------------- ### Sending Notifications (Basic & Advanced) Source: https://context7.com/easychen/serverchan-sdk/llms.txt Examples of sending notifications using the ServerChan SDK, demonstrating both basic usage and advanced options like custom clients and configuration parameters. ```APIDOC ## Sending Notifications ### Basic Send This demonstrates a simple notification send. ### Method `scSend` (or equivalent in other languages) ### Parameters * **sendkey** (string) - Required - The ServerChan send key. * **title** (string) - Required - The title of the notification. * **desp** (string) - Optional - The content/description of the notification. ### Request Example (Dart) ```dart // Basic send ScSendResponse response = await scSend(sendkey, title, desp: desp); if (response.code == 0) { print('Notification sent successfully'); } else { print('Failed: ${response.message}'); } ``` ### Advanced Send This demonstrates sending notifications with advanced options and a custom HTTP client. ### Method `scSend` (or equivalent in other languages) ### Parameters * **sendkey** (string) - Required - The ServerChan send key. * **title** (string) - Required - The title of the notification. * **desp** (string) - Optional - The content/description of the notification. * **options** (object/dictionary/class) - Optional - Configuration options for the notification. * **client** (HTTP client) - Optional - A custom HTTP client instance. ### Request Example (Dart) ```dart // Advanced send with options and custom HTTP client final customClient = http.Client(); try { final options = ScSendOptions( tags: 'app|updates|release', shortDesc: 'v3.0 released', channel: 'wechat|bark' ); final response = await scSend( 'sctp54321t...', // Replace with your sendkey 'User Registration', desp: '**New user:** john@example.com\n**Plan:** Premium\n**Date:** 2025-10-26', options: options, client: customClient ); if (response.code == 0) { print('User notification sent: ${response.message}'); } else { print('Error code ${response.code}: ${response.message}'); } } finally { customClient.close(); } ``` ``` -------------------------------- ### Python Options Dictionary for Notification Customization Source: https://context7.com/easychen/serverchan-sdk/llms.txt Provides an example of the `options` dictionary in Python for configuring notification settings. Demonstrates the use of `tags`, `short` description, `noip`, `channel`, and `openid` parameters. ```python # Python options dictionary options = { "tags": "server|database|backup", "short": "DB backup completed", "noip": 1, "channel": "wechat", "openid": "oXYZ789|oQRS456" } sc_send(sendkey, title, desp, options) ``` -------------------------------- ### ServerChan-SDK Send Message Example Source: https://github.com/easychen/serverchan-sdk/blob/master/pip/README.md An example of sending a system alert message using the `sc_send` function. It includes basic error handling by checking the 'code' in the response dictionary to determine if the message was sent successfully and printing a status message accordingly. ```python from serverchan_sdk import sc_send sendkey = "your_sendkey" title = "系统报警" desp = "服务器 CPU 使用率过高,请立即检查。" response = sc_send(sendkey, title, desp) if response.get("code") == 0: print("消息发送成功!") else: print(f"消息发送失败:{response.get('message')}") ``` -------------------------------- ### JavaScript/TypeScript Response Interface and Examples Source: https://context7.com/easychen/serverchan-sdk/llms.txt Defines the `ScSendResponse` interface for JavaScript/TypeScript, outlining the structure of successful and error responses. Includes example JSON objects for both scenarios. ```javascript // JavaScript/TypeScript Response Interface interface ScSendResponse { code: number; // 0 = success, non-zero = error message: string; // Status message or error description data?: any; // Optional: API-specific response data (format varies by SCT/SC3) } // Example success response { "code": 0, "message": "success", "data": { "pushid": "12345", "readkey": "r_abc123", "error": "SUCCESS", "errno": 0 } } // Example error response { "code": 1, "message": "invalid sendkey", "data": null } ``` -------------------------------- ### PHP SDK: Send Notification Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This example shows how to send a notification using the PHP SDK for Server酱. It uses the `scSend` function, which takes the sendkey, title, desp, and an array of options as arguments. The response is then printed using `print_r`. ```php $ret = scSend('sendkey', 'title', 'desp', ['tags'=>'服务器报警|图片']); print_r($ret); ``` -------------------------------- ### Dart Response Class and Usage Source: https://context7.com/easychen/serverchan-sdk/llms.txt Defines the `ScSendResponse` class in Dart for handling SDK responses. Shows how to instantiate the class and includes an example of error handling during notification sending. ```dart // Dart Response Class class ScSendResponse { int code; String message; dynamic data; ScSendResponse({ required this.code, required this.message, this.data }); } // Usage with error handling final response = await scSend(sendkey, title, desp: message); if (response.code == 0) { print('Success: ${response.message}'); } else { throw Exception('Send failed: ${response.message}'); } ``` -------------------------------- ### Send Message using Server酱 SDK (JavaScript) Source: https://github.com/easychen/serverchan-sdk/blob/master/npm/README.md This snippet demonstrates how to send a message using the scSend function from the serverchan-sdk. It supports custom tags and requires a sendkey, title, and description. The function returns a promise that resolves with the result of the operation. Ensure the 'serverchan-sdk' package is installed. ```javascript import { scSend } from 'serverchan-sdk'; const ret = await scSend('sendkey', 'title', 'description can be markdown', {tags:'服务器报警|图片'}) console.log(ret); ``` -------------------------------- ### Python Response Dictionary and Error Handling Source: https://context7.com/easychen/serverchan-sdk/llms.txt Illustrates the structure of the response object returned by the Python SDK as a dictionary. It includes an example of checking the 'code' field for success and retrieving an error message. ```python # Python Response Dictionary response = { 'code': 0, # Integer: 0 for success 'message': 'success', # String: status description 'data': { # Optional dict: additional response data 'pushid': '12345', 'readkey': 'r_abc123' } } # Error handling example if response['code'] != 0: error_msg = response.get('message', 'Unknown error') print(f"Notification failed: {error_msg}") ``` -------------------------------- ### Dart/Flutter SDK: Send Notification Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This snippet shows how to send a notification using the Dart/Flutter SDK for Server酱. It depends on the 'http' package and uses the `scSend` function. The example includes basic error handling and prints the response code and message. ```dart import 'package:serverchan_sdk/serverchan_sdk.dart'; void main() async { const sendkey = 'your-sendkey'; const title = '测试标题'; const desp = '这是消息的详细内容'; try { ScSendResponse response = await scSend(sendkey, title, desp: desp); print('Response Code: ${response.code}'); print('Response Message: ${response.message}'); } catch (e) { print('Error: $e'); } } ``` -------------------------------- ### Send a message using serverchan-sdk Source: https://github.com/easychen/serverchan-sdk/blob/master/pip/README.md Demonstrates how to import the `sc_send` function from the `serverchan_sdk` library and use it to send a message. It requires a SendKey, title, and message content. Optional parameters like 'template' can be passed via the 'options' dictionary. The response from the ServerChan API is printed. ```python from serverchan_sdk import sc_send # 发送消息 sendkey = "your_sendkey" title = "测试标题" desp = "这是消息内容" options = {"template": "markdown"} # 可选参数 response = sc_send(sendkey, title, desp, options) # 输出响应 print(response) ``` -------------------------------- ### Dart Options Class for Advanced Configuration Source: https://context7.com/easychen/serverchan-sdk/llms.txt Illustrates the `ScSendOptions` class in Dart for advanced notification configuration. Shows how to set parameters such as `tags`, `shortDesc`, `noip`, `channel`, and `openid` for customized message delivery. ```dart // Dart options class final options = ScSendOptions( tags: 'flutter|mobile|release', shortDesc: 'App v2.0 published', noip: 1, channel: 'wechat|telegram', openid: 'oUSER001,oUSER002' ); await scSend(sendkey, title, desp: message, options: options); ``` -------------------------------- ### Options Configuration Source: https://context7.com/easychen/serverchan-sdk/llms.txt Details the advanced configuration options available for customizing notification behavior, such as tags, short descriptions, channel selection, and specific user targeting. ```APIDOC ## Options Configuration Advanced configuration options allow customization of notification behavior across different ServerChan versions. ### JavaScript Options Interface ```javascript // JavaScript Options Interface const options = { tags: 'monitoring|alert|urgent', // SC3 only: pipe-separated tags short: 'Brief summary text', // Both: card summary (useful when desp is markdown) noip: 1, // SCT only: hide caller IP (1 = hide) channel: 'wechat|email|bark', // SCT only: delivery channels (pipe-separated) openid: 'oABC123,oDEF456' // SCT only: WeChat OpenIDs (comma or pipe-separated) }; await scSend(sendkey, title, desp, options); ``` ### Python Options Dictionary ```python # Python options dictionary options = { "tags": "server|database|backup", "short": "DB backup completed", "noip": 1, "channel": "wechat", "openid": "oXYZ789|oQRS456" } sc_send(sendkey, title, desp, options) ``` ### Dart Options Class ```dart // Dart options class final options = ScSendOptions( tags: 'flutter|mobile|release', shortDesc: 'App v2.0 published', noip: 1, channel: 'wechat|telegram', openid: 'oUSER001,oUSER002' ); await scSend(sendkey, title, desp: message, options: options); ``` ``` -------------------------------- ### TypeScript: Server酱 SDK Implementation Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This TypeScript code provides a reference implementation for the Server酱 SDK. It defines interfaces for optional send parameters (`ScSendOptions`) and the response structure (`ScSendResponse`). The `scSend` function dynamically constructs the URL based on the sendkey format and sends a POST request with the provided data. ```typescript import fetch from 'cross-fetch'; // ScSendOptions defines the optional parameters for the push function export interface ScSendOptions { /** sctp specific: tag list, multiple tags separated by vertical bars */ tags?: string; /** sctp and non-sctp: short description for message card */ short?: string; /** non-sctp: whether to hide calling IP, 1 to hide */ noip?: 1; /** non-sctp: message channel for push, multiple channels separated by vertical bars */ channel?: string; /** non-sctp: openid for message抄送, multiple openids separated by commas or vertical bars */ openid?: string; } // ScSendResponse defines the response result of the push function export interface ScSendResponse { /** status code */ code: number; /** message */ message: string; /** optional return data */ data?: any; } // Call Server酱 push function export async function scSend( sendkey: string, title: string, desp: string = '', options: ScSendOptions = {} ): Promise { const url = sendkey.startsWith('sctp') ? `https://${sendkey}.push.ft07.com/send` : `https://sctapi.ftqq.com/${sendkey}.send`; const params = { title, desp, ...options, }; const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8', }, body: JSON.stringify(params), }); const result = await response.json() as ScSendResponse; return result; } ``` -------------------------------- ### Send Basic Notification in Dart Source: https://context7.com/easychen/serverchan-sdk/llms.txt Demonstrates sending a basic notification using the ServerChan SDK in Dart. It includes basic error handling and prints the response code and message. Dependencies include the 'http' package for advanced usage. ```dart import 'package:serverchan_sdk/serverchan_sdk.dart'; import 'package:http/http.dart' as http; Future sendBasicNotification() async { final sendkey = 'YOUR_SENDKEY'; final title = 'Test Notification'; final desp = 'This is a test message.'; try { // Basic send ScSendResponse response = await scSend(sendkey, title, desp: desp); print('Response Code: ${response.code}'); print('Response Message: ${response.message}'); if (response.code == 0) { print('Notification sent successfully'); print('Response data: ${response.data}'); } else { print('Failed: ${response.message}'); } } catch (e) { print('Error sending notification: $e'); } } ``` -------------------------------- ### Python SDK: Send Notification Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This snippet illustrates sending a notification with the Python SDK for Server酱. It imports the `sc_send` function and demonstrates its usage with a sendkey, title, desp, and an optional 'options' dictionary which can include parameters like 'tags'. ```python from serverchan_sdk import sc_send # Send message sendkey = "..." title = "测试标题" desp = "这是消息内容" options = {"tags": "服务器报警|图片"} # Optional parameters response = sc_send(sendkey, title, desp, options) ``` -------------------------------- ### JavaScript Options for Notification Configuration Source: https://context7.com/easychen/serverchan-sdk/llms.txt Details the `options` object in JavaScript for customizing notification delivery. Covers parameters like `tags` (SC3 only), `short` description, `noip` (SCT only), `channel`, and `openid` (SCT only). ```javascript // JavaScript Options Interface const options = { tags: 'monitoring|alert|urgent', // SC3 only: pipe-separated tags short: 'Brief summary text', // Both: card summary (useful when desp is markdown) noip: 1, // SCT only: hide caller IP (1 = hide) channel: 'wechat|email|bark', // SCT only: delivery channels (pipe-separated) openid: 'oABC123,oDEF456' // SCT only: WeChat OpenIDs (comma or pipe-separated) }; await scSend(sendkey, title, desp, options); ``` -------------------------------- ### 发送消息使用 scSend 函数 (JavaScript) Source: https://github.com/easychen/serverchan-sdk/blob/master/npm/test/test.html 演示如何使用 serverchan-sdk 中的 scSend 函数发送通知。它接收 sendkey、标题和描述作为输入,并返回一个 Promise,解析为响应结果。此示例监听一个表单的提交事件,获取用户输入后调用 scSend,并将结果或错误显示在页面上。 ```javascript import { scSend } from 'https://unpkg.com/serverchan-sdk'; const form = document.getElementById('sendForm'); const responsePre = document.getElementById('response'); form.addEventListener('submit', async function (event) { event.preventDefault(); const sendkey = document.getElementById('sendkey').value; const title = document.getElementById('title').value; const desp = document.getElementById('desp').value; try { const result = await scSend(sendkey, title, desp); responsePre.textContent = JSON.stringify(result, null, 2); } catch (error) { responsePre.textContent = '发送失败: ' + error.message; } }); ``` -------------------------------- ### Server酱 SDK Options Reference (JSONC) Source: https://github.com/easychen/serverchan-sdk/blob/master/npm/README.md This section details the available options for the serverchan-sdk when sending messages. These options control features like tags, message card descriptions, IP hiding, channel selection, and message抄送 (cc) for SC3 and SCT versions of Server酱. The format is JSONC for clarity. ```jsonc { /** SC3专用:标签列表,多个标签使用竖线分隔 */ tags?: string; /** SC3和SCT:消息卡片的简短描述 */ short?: string; /** SCT:是否隐藏调用IP,1为隐藏 */ noip?: 1; /** SCT:推送使用的消息通道,多个通道值用竖线隔开 */ channel?: string; /** SCT:消息抄送的 openid,多个 openid 用逗号或竖线分隔 */ openid?: string; } ``` -------------------------------- ### JavaScript SDK: Send Notification Source: https://github.com/easychen/serverchan-sdk/blob/master/README.md This snippet demonstrates how to send a notification using the JavaScript SDK for Server酱. It requires the 'serverchan-sdk' package and utilizes an asynchronous function `scSend` to dispatch messages. The function accepts sendkey, title, desp, and optional parameters like 'tags'. ```javascript import {scSend} from 'serverchan-sdk'; const sendkey = '...'; // Replace with your actual Server酱 sendkey const title = 'Test Notification'; const desp = 'This is a test message'; const response = await scSend(sendkey, title, desp, { tags: '服务器报警|报告' }); console.log('Response:', response); ``` -------------------------------- ### Send Notification (Python) Source: https://context7.com/easychen/serverchan-sdk/llms.txt Enables push notifications through the ServerChan API for Python applications. Supports simple messages and advanced options including tags, short descriptions, and custom channels, with error handling for invalid sendkeys. ```python from serverchan_sdk import sc_send # Simple notification sendkey = "SCT987654321FEDCBA" title = "Backup Complete" desp = "Database backup completed successfully.\n\n**Size:** 2.5GB\n**Duration:** 15 minutes" try: response = sc_send(sendkey, title, desp) print(f"Code: {response['code']}") print(f"Message: {response['message']}") if response['code'] == 0: print("Notification delivered") else: print(f"Error: {response['message']}") except ValueError as e: print(f"Invalid sendkey format: {e}") except Exception as e: print(f"Request failed: {e}") # Notification with tags and short description (SC3 version) options = { "tags": "monitoring|alert|critical", "short": "High CPU detected", "channel": "wechat" } response = sc_send( "sctp98765t...", "CPU Usage Alert", "Server cpu01 is running at 95% capacity for the last 10 minutes.\n\n" \ "**Action Required:** Scale up instances or investigate process load.", options ) # Process response if response.get('code') == 0: print(f"Alert sent. Data: {response.get('data')}") else: print(f"Failed to send alert: {response.get('message')}") ``` -------------------------------- ### Send Advanced Notification with Options in Dart Source: https://context7.com/easychen/serverchan-sdk/llms.txt Shows how to send an advanced notification with custom options and an HTTP client. This includes setting tags, short descriptions, and delivery channels. It ensures the custom HTTP client is closed after use. ```dart import 'package:serverchan_sdk/serverchan_sdk.dart'; import 'package:http/http.dart' as http; Future sendAdvancedNotification() async { // Advanced send with options and custom HTTP client final customClient = http.Client(); try { final options = ScSendOptions( tags: 'app|updates|release', shortDesc: 'v3.0 released', channel: 'wechat|bark' ); final response = await scSend( 'sctp54321t...', // Replace with your sendkey 'User Registration', desp: '**New user:** john@example.com\n**Plan:** Premium\n**Date:** 2025-10-26', options: options, client: customClient ); if (response.code == 0) { print('User notification sent: ${response.message}'); } else { print('Error code ${response.code}: ${response.message}'); } } finally { customClient.close(); } } ``` -------------------------------- ### Send Notification (JavaScript/Node.js) Source: https://context7.com/easychen/serverchan-sdk/llms.txt Sends push notifications via ServerChan API using automatic version detection based on the sendkey prefix. Supports basic and advanced notifications with options like tags, short descriptions, channels, and IP masking. ```javascript import { scSend } from 'serverchan-sdk'; // Basic notification const sendkey = 'SCT123456789ABCDEF'; const title = 'Server Alert'; const desp = '## System Status\n\nCPU usage: 85%\n\n![Status](https://example.com/chart.png)'; try { const response = await scSend(sendkey, title, desp); console.log('Status:', response.code); // 0 for success console.log('Message:', response.message); // "success" or error message console.log('Data:', response.data); // Additional API response data } catch (error) { console.error('Send failed:', error.message); } // Advanced notification with options (SC3/sctp version) const sctpKey = 'sctp12345t...'; const optionsResponse = await scSend( sctpKey, 'Deployment Complete', 'Version 2.0 deployed successfully at ' + new Date().toISOString(), { tags: 'deployment|production|success', short: 'v2.0 deployed', channel: 'wechat|email', noip: 1 } ); // Handle response if (optionsResponse.code === 0) { console.log('Notification sent successfully'); } else { console.error('Failed:', optionsResponse.message); } ``` -------------------------------- ### Response Format Source: https://context7.com/easychen/serverchan-sdk/llms.txt Details the standard response object structure returned by the SDK, including success and error codes, messages, and optional data. ```APIDOC ## Response Format All SDK implementations return a standardized response object with consistent structure across languages. ### JavaScript/TypeScript Response Interface ```javascript interface ScSendResponse { code: number; // 0 = success, non-zero = error message: string; // Status message or error description data?: any; // Optional: API-specific response data (format varies by SCT/SC3) } // Example success response { "code": 0, "message": "success", "data": { "pushid": "12345", "readkey": "r_abc123", "error": "SUCCESS", "errno": 0 } } // Example error response { "code": 1, "message": "invalid sendkey", "data": null } ``` ### Python Response Dictionary ```python # Python Response Dictionary response = { 'code': 0, # Integer: 0 for success 'message': 'success', # String: status description 'data': { # Optional dict: additional response data 'pushid': '12345', 'readkey': 'r_abc123' } } # Error handling example if response['code'] != 0: error_msg = response.get('message', 'Unknown error') print(f"Notification failed: {error_msg}") ``` ### Dart Response Class ```dart // Dart Response Class class ScSendResponse { int code; String message; dynamic data; ScSendResponse({ required this.code, required this.message, this.data }); } // Usage with error handling final response = await scSend(sendkey, title, desp: message); if (response.code == 0) { print('Success: ${response.message}'); } else { throw Exception('Send failed: ${response.message}'); } ``` ``` -------------------------------- ### Send Notification (Dart/Flutter) Source: https://context7.com/easychen/serverchan-sdk/llms.txt Provides asynchronous push notification support for Dart and Flutter applications. This function integrates with ServerChan API, handling HTTP requests and response processing for mobile and server environments. ```dart import 'package:serverchan_sdk/serverchan_sdk.dart'; import 'package:http/http.dart' as http; void main() async { const sendkey = 'SCT111222333AAABBB'; const title = 'App Update Available'; const desp = ''' ## New Version 3.0 ''' // Example usage would follow here, typically involving a call to scSend // For instance: // final response = await scSend(sendkey, title, desp); // print('Response: ${response.message}'); } // Note: The provided snippet is incomplete and mainly shows imports and setup. // A full implementation would require the actual scSend function call and response handling. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.