### Send File Message Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md Example of sending a file message using the SDK. Requires appropriate imports and client initialization. ```python from lark_oapi.api.im.v1.file import SendFileReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Prepare request body req_body = SendFileReqBody( file_key="file_key", message_type="file", content={"file_key": "file_key"}, receive_id="ou_xxxx", receive_id_type="open_id", ) # Send file message resp = api.im.v1.file.send(req_body) # Process response if resp.code == 0: print(resp.data) else: print(resp.error) ``` -------------------------------- ### Create App and Tables Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md Example for creating a multidimensional table application and adding data tables to it. This involves multiple steps and API calls. ```python from lark_oapi.api.base.v1.app import CreateAppReqBody from lark_oapi.api.base.v1.table import CreateTableReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Create app app_req_body = CreateAppReqBody( name="app_name", description="app_description", ) app_resp = api.base.v1.app.create(app_req_body) # Create table if app_resp.code == 0: table_req_body = CreateTableReqBody( app_token=app_resp.data.app_token, name="table_name", description="table_description", ) table_resp = api.base.v1.table.create(table_req_body) if table_resp.code == 0: print(table_resp.data) else: print(table_resp.error) else: print(app_resp.error) ``` -------------------------------- ### Request Options and Token Management Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Configure per-request options for ISV apps, custom tokens, or additional headers. This example demonstrates setting tenant keys and manual token management. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * # For ISV (marketplace) apps, configure tenant_key per request client = lark.Client.builder() \ .app_id("cli_xxx") \ .app_secret("xxx") \ .app_type(lark.AppType.ISV) \ .build() request = CreateMessageRequest.builder() \ .receive_id_type("open_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("ou_xxx") .msg_type("text") .content('{"text": "Hello tenant!"}') .build()) .build() # Build request options with tenant key option = lark.RequestOption.builder() \ .tenant_key("tenant_xxx") \ .build() response = client.im.v1.message.create(request, option) # For apps with manual token management client_manual = lark.Client.builder() \ .app_id("cli_xxx") \ .app_secret("xxx") \ .enable_set_token(True) \ .build() option_with_token = lark.RequestOption.builder() \ .tenant_access_token("t-xxx") \ .headers({"X-Custom-Header": "value"}) \ .build() response = client_manual.im.v1.message.create(request, option_with_token) ``` -------------------------------- ### WebSocket Long Connection Client Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Set up a WebSocket client to receive events in real-time. This example demonstrates handling message receive events and custom events. Ensure your app ID and secret are valid. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import P2ImMessageReceiveV1 def handle_message(data: P2ImMessageReceiveV1) -> None: message = data.event.message print(f"[WebSocket] Received: {message.content}") print(f"Message ID: {message.message_id}") def handle_custom_event(data: lark.CustomizedEvent) -> None: print(f"Custom event received: {lark.JSON.marshal(data)}") # Build event handler event_handler = lark.EventDispatcherHandler.builder("", "") \ .register_p2_im_message_receive_v1(handle_message) \ .register_p1_customized_event("custom_event_key", handle_custom_event) \ .build() # Create and start WebSocket client ws_client = lark.ws.Client( app_id="cli_xxx", app_secret="xxx", event_handler=event_handler, log_level=lark.LogLevel.DEBUG, auto_reconnect=True ) # Start listening (blocking call) ws_client.start() ``` -------------------------------- ### Create a Calendar Event Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Creates a new event in a specified calendar. Requires calendar ID, event summary, description, start and end times, and attendee ability settings. ```python import lark_oapi as lark from lark_oapi.api.calendar.v4 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Create a calendar event event_request = CreateCalendarEventRequest.builder() \ .calendar_id("feishu.cn_xxx@group.calendar.feishu.cn") \ .request_body(CreateCalendarEventRequestBody.builder() .summary("Team Meeting") .description("Weekly sync meeting") .start_time(TimeInfo.builder() .timestamp("1700000000") .timezone("Asia/Shanghai") .build()) .end_time(TimeInfo.builder() .timestamp("1700003600") .timezone("Asia/Shanghai") .build()) .attendee_ability("can_see_others") .build()) .build() response = client.calendar.v4.calendar_event.create(event_request) if response.success(): print(f"Event created: {response.data.event.event_id}") ``` -------------------------------- ### Async API Calls with asyncio Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Utilize asynchronous counterparts of API methods for non-blocking operations using asyncio. This example shows sending messages and getting chat information asynchronously. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * import asyncio async def send_messages(): client = lark.Client.builder() \ .app_id("cli_xxx") \ .app_secret("xxx") \ .build() # Async message creation request = CreateMessageRequest.builder() \ .receive_id_type("open_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("ou_xxx") .msg_type("text") .content('{"text": "Async hello!"}') .build()) .build() # Use acreate instead of create for async response = await client.im.v1.message.acreate(request) if response.success(): print(f"Async message sent: {response.data.message_id}") # Async get chat info chat_request = GetChatRequest.builder() \ .chat_id("oc_xxx") \ .build() chat_response = await client.im.v1.chat.aget(chat_request) if chat_response.success(): print(f"Chat name: {chat_response.data.name}") # Run async code asyncio.run(send_messages()) ``` -------------------------------- ### Copy and Paste Cell Data by Range Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md This example demonstrates copying and pasting cell data within a specified range in a spreadsheet. It requires sheet ID and range details. ```python from lark_oapi.api.sheets.v1.spreadsheet_sheet_cell import SpreadsheetSheetCellReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Prepare request body req_body = SpreadsheetSheetCellReqBody( spreadsheet_token="spreadsheet_token", sheet_token="sheet_token", range="A1:B2", "copy_from": { "spreadsheet_token": "spreadsheet_token", "sheet_token": "sheet_token", "range": "C1:D2" } ) # Copy and paste cell data resp = api.sheets.v1.spreadsheet_sheet_cell.copy(req_body) # Process response if resp.code == 0: print(resp.data) else: print(resp.error) ``` -------------------------------- ### Batch Get User IDs Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Fetches user IDs by providing a list of user emails or mobile numbers. Specify the desired user ID type for the response. ```python batch_request = BatchGetIdUserRequest.builder() \ .user_id_type("open_id") \ .request_body(BatchGetIdUserRequestBody.builder() .emails(["user1@example.com", "user2@example.com"]) .build()) .build() batch_response = client.contact.v3.user.batch_get_id(batch_request) ``` -------------------------------- ### Initialize Feishu SDK Client Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Create a client instance using app credentials. Supports basic and full configuration options including domain, timeout, log level, and app type. ```python import lark_oapi as lark # Create client with basic configuration client = lark.Client.builder() \ .app_id("cli_your_app_id") \ .app_secret("your_app_secret") \ .build() ``` ```python import lark_oapi as lark # Create client with full configuration options client = lark.Client.builder() \ .app_id("cli_your_app_id") \ .app_secret("your_app_secret") \ .domain(lark.FEISHU_DOMAIN) # or lark.LARK_DOMAIN for international .timeout(30.0) # request timeout in seconds .log_level(lark.LogLevel.DEBUG) \ .app_type(lark.AppType.SELF) # SELF for self-built apps, ISV for marketplace apps .build() ``` -------------------------------- ### Client Initialization Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Initialize the Feishu client with your application credentials. Supports basic and full configuration options including domain, timeout, log level, and app type. ```APIDOC ## Client Initialization Create a client instance with app credentials to access all Feishu APIs. The client manages authentication tokens automatically and provides access to service-specific API modules. ```python import lark_oapi as lark # Create client with basic configuration client = lark.Client.builder() \ .app_id("cli_your_app_id") \ .app_secret("your_app_secret") \ .build() # Create client with full configuration options client = lark.Client.builder() \ .app_id("cli_your_app_id") \ .app_secret("your_app_secret") \ .domain(lark.FEISHU_DOMAIN) # or lark.LARK_DOMAIN for international .timeout(30.0) # request timeout in seconds .log_level(lark.LogLevel.DEBUG) \ .app_type(lark.AppType.SELF) # SELF for self-built apps, ISV for marketplace apps .build() ``` ``` -------------------------------- ### Download Media by Range Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md Fetches a list of all media materials within a specified range in a spreadsheet. Requires spreadsheet and sheet tokens. ```python from lark_oapi.api.sheets.v1.spreadsheet_sheet_media import SpreadsheetSheetMediaReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Prepare request body req_body = SpreadsheetSheetMediaReqBody( spreadsheet_token="spreadsheet_token", sheet_token="sheet_token", range="A1:B2" ) # Download media by range resp = api.sheets.v1.spreadsheet_sheet_media.list(req_body) # Process response if resp.code == 0: print(resp.data) else: print(resp.error) ``` -------------------------------- ### Send Image Message Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md Demonstrates how to send an image message. Ensure the image file is accessible and its key is correctly provided. ```python from lark_oapi.api.im.v1.image import SendImageReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Prepare request body req_body = SendImageReqBody( image_key="image_key", message_type="image", content={"image_key": "image_key"}, receive_id="ou_xxxx", receive_id_type="open_id", ) # Send image message resp = api.im.v1.image.send(req_body) # Process response if resp.code == 0: print(resp.data) else: print(resp.error) ``` -------------------------------- ### Create and Manage Chat Groups Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Programmatically create new chat groups, set their name, description, mode, type, and owner. Also includes functionality to add members to existing chats. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Create a new chat group create_request = CreateChatRequest.builder() \ .request_body(CreateChatRequestBody.builder() .name("Project Discussion") .description("A group for project collaboration") .chat_mode("group") .chat_type("private") .owner_id("ou_xxx") .user_id_list(["ou_user1", "ou_user2"]) .build()) \ .build() response = client.im.v1.chat.create(create_request) if response.success(): chat_id = response.data.chat_id print(f"Chat created: {chat_id}") ``` ```python # Add members to a chat add_members_request = CreateChatMembersRequest.builder() \ .chat_id("oc_xxx") \ .member_id_type("open_id") \ .request_body(CreateChatMembersRequestBody.builder() .id_list(["ou_new_user1", "ou_new_user2"]) .build()) \ .build() add_response = client.im.v1.chat_members.create(add_members_request) ``` -------------------------------- ### Create a Folder in Drive Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Creates a new folder within the Lark Drive. Requires a parent folder token and the desired name for the new folder. ```python import lark_oapi as lark from lark_oapi.api.drive.v1 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Create a folder folder_request = CreateFolderFileRequest.builder() \ .request_body(CreateFolderFileRequestBody.builder() .name("New Project Folder") .folder_token("fldcnxxx") # parent folder token .build()) .build() response = client.drive.v1.file.create_folder(folder_request) if response.success(): print(f"Folder created: {response.data.token}") ``` -------------------------------- ### List Files in a Folder Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Retrieves a list of files and subfolders within a specified folder. Supports pagination with `page_size`. ```python import lark_oapi as lark from lark_oapi.api.drive.v1 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # List files in a folder list_request = ListFileRequest.builder() \ .folder_token("fldcnxxx") \ .page_size(20) \ .build() list_response = client.drive.v1.file.list(list_request) if list_response.success(): for file in list_response.data.files: print(f"File: {file.name} (type: {file.type})") ``` -------------------------------- ### Copy a File in Drive Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Copies an existing file to a new location within the drive. Requires the source file token, new file name, type, and destination folder token. ```python import lark_oapi as lark from lark_oapi.api.drive.v1 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Copy a file copy_request = CopyFileRequest.builder() \ .file_token("boxcnxxx") \ .request_body(CopyFileRequestBody.builder() .name("Copy of Document") .type("docx") .folder_token("fldcnxxx") .build()) .build() copy_response = client.drive.v1.file.copy(copy_request) ``` -------------------------------- ### Handle Feishu Webhook Events Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Sets up a Flask application to receive and dispatch Feishu webhook events. Includes handlers for message receives and user creation events. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import P2ImMessageReceiveV1 from lark_oapi.api.contact.v3 import P2ContactUserCreatedV3 from flask import Flask, request app = Flask(__name__) # Define event handlers def handle_message_receive(data: P2ImMessageReceiveV1) -> None: message = data.event.message print(f"Received message: {message.content}") print(f"From: {data.event.sender.sender_id.open_id}") print(f"Chat: {message.chat_id}") def handle_user_created(data: P2ContactUserCreatedV3) -> None: user = data.event.object print(f"New user created: {user.name} ({user.open_id})") # Build the event dispatcher event_handler = lark.EventDispatcherHandler.builder( encrypt_key="your_encrypt_key", verification_token="your_verification_token" ) \ .register_p2_im_message_receive_v1(handle_message_receive) \ .register_p2_contact_user_created_v3(handle_user_created) \ .build() @app.route("/webhook/event", methods=["POST"]) def webhook(): from lark_oapi.adapter.flask import parse_req, parse_resp req = parse_req() resp = event_handler.do(req) return parse_resp(resp) if __name__ == "__main__": app.run(port=8080) ``` -------------------------------- ### Handle Card Action Callbacks Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Implement a Flask endpoint to receive and process interactive card actions from Lark. Ensure your encrypt key and verification token are correctly configured. ```python import lark_oapi as lark from lark_oapi.event.callback.model.p2_card_action_trigger import ( P2CardActionTrigger, P2CardActionTriggerResponse ) from flask import Flask app = Flask(__name__) def handle_card_action(data: P2CardActionTrigger) -> P2CardActionTriggerResponse: action = data.event.action print(f"Card action: {action.tag}") print(f"Value: {action.value}") print(f"User: {data.event.operator.open_id}") # Return a toast notification response return P2CardActionTriggerResponse({ "toast": { "type": "success", "content": "Action processed successfully!" } }) event_handler = lark.EventDispatcherHandler.builder("encrypt_key", "verification_token") \ .register_p2_card_action_trigger(handle_card_action) \ .build() @app.route("/webhook/card", methods=["POST"]) def card_webhook(): from lark_oapi.adapter.flask import parse_req, parse_resp return parse_resp(event_handler.do(parse_req())) ``` -------------------------------- ### List Users by Department Source: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/README.md Retrieves a list of all users within a specific department. Requires the department ID. ```python from lark_oapi.api.contact.v3.user import ListUserReqBody from lark_oapi.core.model import Config, i18n_resource from lark_oapi.core.token_store import InMemoryTokenStore from lark_oapi.core.http import HttpClient from lark_oapi.api import Api # Initialize configuration conf = Config( ொள்_id="YOUR_APP_ID", ொள்_secret="YOUR_APP_SECRET", tenant_access_token_lifetime=600, tenant_access_token_path="", user_access_token_lifetime=7200, user_access_token_path="", encrypt_key="YOUR_ENCRYPT_KEY", verification_token="YOUR_VERIFICATION_TOKEN", store=InMemoryTokenStore(), ) # Initialize API api = Api(conf) # Prepare request body req_body = ListUserReqBody( department_id="department_id", department_id_type="open_department_id", user_id_type="open_id", page_size=50, page_token="", ) # List users by department resp = api.contact.v3.user.list(req_body) # Process response if resp.code == 0: print(resp.data) else: print(resp.error) ``` -------------------------------- ### Manage Chat Groups Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Create, update, and manage chat groups, including adding and removing members, and configuring group settings. ```APIDOC ## Manage Chat Groups Create, update, and manage chat groups including adding/removing members and configuring group settings. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Create a new chat group create_request = CreateChatRequest.builder() \ .request_body(CreateChatRequestBody.builder() .name("Project Discussion") .description("A group for project collaboration") .chat_mode("group") .chat_type("private") .owner_id("ou_xxx") .user_id_list(["ou_user1", "ou_user2"]) .build()) \ .build() response = client.im.v1.chat.create(create_request) if response.success(): chat_id = response.data.chat_id print(f"Chat created: {chat_id}") # Add members to a chat add_members_request = CreateChatMembersRequest.builder() \ .chat_id("oc_xxx") \ .member_id_type("open_id") \ .request_body(CreateChatMembersRequestBody.builder() .id_list(["ou_new_user1", "ou_new_user2"]) .build()) \ .build() add_response = client.im.v1.chat_members.create(add_members_request) ``` ``` -------------------------------- ### Retrieve User Information Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Fetch user details such as name and email using their unique user ID. Requires specifying the user ID type for accurate retrieval. ```python import lark_oapi as lark from lark_oapi.api.contact.v3 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Get user information by user ID get_request = GetUserRequest.builder() \ .user_id("ou_xxx") \ .user_id_type("open_id") \ .build() response = client.contact.v3.user.get(get_request) if response.success(): user = response.data.user print(f"Name: {user.name}, Email: {user.email}") ``` -------------------------------- ### List Users in a Department Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Retrieves a list of users within a specified department. Requires department ID and user ID type. Supports pagination. ```python list_request = FindByDepartmentUserRequest.builder() \ .department_id("od_xxx") \ .user_id_type("open_id") \ .page_size(50) \ .build() list_response = client.contact.v3.user.find_by_department(list_request) if list_response.success(): for user in list_response.data.items: print(f"User: {user.name} ({user.open_id})") ``` -------------------------------- ### User and Contact Management Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Manage users, departments, and organizational structure through the Contact API. ```APIDOC ## User and Contact Management Manage users, departments, and organizational structure through the Contact API. ```python import lark_oapi as lark from lark_oapi.api.contact.v3 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Get user information by user ID get_request = GetUserRequest.builder() \ .user_id("ou_xxx") \ .user_id_type("open_id") \ .build() response = client.contact.v3.user.get(get_request) if response.success(): user = response.data.user print(f"Name: {user.name}, Email: {user.email}") ``` ``` -------------------------------- ### List Calendar Events Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Retrieves a list of events within a specified time range for a given calendar. Requires calendar ID and start/end timestamps. ```python import lark_oapi as lark from lark_oapi.api.calendar.v4 import * client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # List calendar events list_request = ListCalendarEventRequest.builder() \ .calendar_id("feishu.cn_xxx@group.calendar.feishu.cn") \ .start_time("1700000000") \ .end_time("1700100000") \ .build() list_response = client.calendar.v4.calendar_event.list(list_request) ``` -------------------------------- ### Send Message (IM API) Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Send various types of messages (text, rich text, interactive cards, files) to users or group chats using the IM API. ```APIDOC ## Send Message (IM API) Send text, rich text, interactive cards, and file messages to users or group chats using the instant messaging API. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * import json client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Send a text message to a user request = CreateMessageRequest.builder() \ .receive_id_type("open_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("ou_xxx") .msg_type("text") .content(json.dumps({"text": "Hello from Feishu SDK!"})) .build()) \ .build() response = client.im.v1.message.create(request) if response.success(): print(f"Message sent! Message ID: {response.data.message_id}") else: print(f"Failed: {response.code} - {response.msg}") # Send an interactive card message card_content = { "type": "template", "data": { "template_id": "your_template_id", "template_variable": {"name": "User"} } } card_request = CreateMessageRequest.builder() \ .receive_id_type("chat_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("oc_xxx") .msg_type("interactive") .content(json.dumps(card_content)) .build()) \ .build() card_response = client.im.v1.message.create(card_request) ``` ``` -------------------------------- ### Send Text and Interactive Messages Source: https://context7.com/larksuite/oapi-sdk-python/llms.txt Send various message types including text and interactive cards to users or group chats. Ensure correct receive ID type and message content formatting. ```python import lark_oapi as lark from lark_oapi.api.im.v1 import * import json client = lark.Client.builder().app_id("cli_xxx").app_secret("xxx").build() # Send a text message to a user request = CreateMessageRequest.builder() \ .receive_id_type("open_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("ou_xxx") .msg_type("text") .content(json.dumps({"text": "Hello from Feishu SDK!"})) .build()) \ .build() response = client.im.v1.message.create(request) if response.success(): print(f"Message sent! Message ID: {response.data.message_id}") else: print(f"Failed: {response.code} - {response.msg}") ``` ```python # Send an interactive card message card_content = { "type": "template", "data": { "template_id": "your_template_id", "template_variable": {"name": "User"} } } card_request = CreateMessageRequest.builder() \ .receive_id_type("chat_id") \ .request_body(CreateMessageRequestBody.builder() .receive_id("oc_xxx") .msg_type("interactive") .content(json.dumps(card_content)) .build()) \ .build() card_response = client.im.v1.message.create(card_request) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.