tourze/wechat-work-app-chat-bundle

企业微信群聊管理服务组件

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/wechat-work-app-chat-bundle

0.0.1 2025-06-03 15:14 UTC

This package is auto-updated.

Last update: 2025-11-03 06:28:16 UTC


README

PHP Version License Build Status Code Coverage

English | 中文

Enterprise WeChat group chat management bundle for Symfony applications.

Features

  • Create and manage Enterprise WeChat group chats
  • Send text, markdown, image, and file messages to group chats
  • Automatic message queue with retry mechanism
  • Symfony command-line tools for batch operations
  • Event-driven message sending

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Enterprise WeChat Work API credentials

Installation

composer require tourze/wechat-work-app-chat-bundle

Configuration

Register the bundle in your application:

// config/bundles.php
return [
    // ...
    WechatWorkAppChatBundle\WechatWorkAppChatBundle::class => ['all' => true],
];

Usage

Services

AppChatService

Manages Enterprise WeChat group chats:

use WechatWorkAppChatBundle\Service\AppChatService;

// Create a new group chat
$appChatService->createAppChat($chatId, $name, $owner, $userList);

// Update group chat information
$appChatService->updateAppChat($appChat);

// Sync group chat information from WeChat Work API
$appChatService->syncAppChat($appChat);

// Sync all unsynced group chats
$appChatService->syncUnsynced();

MessageService

Handles message sending to group chats:

use WechatWorkAppChatBundle\Service\MessageService;

// Send text message
$messageService->sendText($chatId, $content, $mentionedList = [], $mentionedMobileList = []);

// Send markdown message
$messageService->sendMarkdown($chatId, $content);

// Send image message
$messageService->sendImage($chatId, $mediaId);

// Send file message
$messageService->sendFile($chatId, $mediaId);

// Send all unsent messages
$messageService->sendUnsent();

Entities

  • AppChat: Represents an Enterprise WeChat group chat
  • TextMessage: Plain text messages with @mention support
  • MarkdownMessage: Markdown formatted messages
  • ImageMessage: Image messages with media ID
  • FileMessage: File messages with media ID

Commands

Send Unsent Messages

Sends all queued messages that haven't been sent yet:

bin/console wechat-work:app-chat:send-unsent

This command:

  • Retrieves all unsent messages from the database
  • Attempts to send each message via WeChat Work API
  • Updates message status upon successful sending
  • Handles errors gracefully with detailed output

Sync Group Chats

Synchronizes group chat information with WeChat Work API:

bin/console wechat-work:app-chat:sync

This command:

  • Fetches all unsynced group chats
  • Retrieves latest information from WeChat Work API
  • Updates local database with current group chat details
  • Reports sync status and any errors

Event Subscribers

The bundle includes an automatic message sending subscriber that triggers when new messages are persisted to the database. This ensures messages are sent immediately when created.

Examples

Creating and Sending Messages

// Create a text message
$textMessage = new TextMessage();
$textMessage->setChatId('your-chat-id');
$textMessage->setContent('Hello, World!');
$textMessage->setMentionedList(['@all']); // Mention everyone

// Save to database (automatically triggers sending)
$entityManager->persist($textMessage);
$entityManager->flush();

// Send markdown message directly
$messageService->sendMarkdown('your-chat-id', '# Important Notice\n\nPlease check the latest updates.');

Managing Group Chats

// Create a new group chat
$appChat = new AppChat();
$appChat->setChatId('tech-team-001');
$appChat->setName('Tech Team Discussion');
$appChat->setOwner('john.doe');
$appChat->setUserList(['john.doe', 'jane.smith', 'bob.wilson']);

$entityManager->persist($appChat);
$entityManager->flush();

// Sync with WeChat Work API
$appChatService->syncAppChat($appChat);

Testing

Run the test suite:

./vendor/bin/phpunit packages/wechat-work-app-chat-bundle/tests

Contributing

Please read the main repository's contributing guidelines before submitting pull requests.

License

This bundle is licensed under the same license as the parent monorepo.