feat(im): add WeChat integration with QR code login and long-polling support
- Extended the IMChannel interface to include WeChat as a platform, supporting long-polling mode and full output mode. - Implemented WeChat QR code login functionality, allowing users to authenticate via a QR code. - Added new API endpoints for generating and polling the status of WeChat QR codes. - Updated the frontend to handle WeChat-specific UI elements and interactions, including dynamic form adjustments based on the selected platform. - Enhanced localization files to include WeChat-related translations. - Introduced a WeChat adapter for message handling and file downloading via the iLink Bot API.
This commit is contained in:
@@ -61,6 +61,7 @@ import (
|
||||
"github.com/Tencent/WeKnora/internal/im/mattermost"
|
||||
"github.com/Tencent/WeKnora/internal/im/slack"
|
||||
"github.com/Tencent/WeKnora/internal/im/telegram"
|
||||
"github.com/Tencent/WeKnora/internal/im/wechat"
|
||||
"github.com/Tencent/WeKnora/internal/im/wecom"
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/docparser"
|
||||
infra_web_search "github.com/Tencent/WeKnora/internal/infrastructure/web_search"
|
||||
@@ -1277,6 +1278,32 @@ func registerIMAdapterFactories(imService *imPkg.Service) {
|
||||
adapter := mattermost.NewAdapter(client, outgoingToken, botUserID, postReplyToMain)
|
||||
return adapter, func() {}, nil
|
||||
})
|
||||
// Register WeChat adapter factory
|
||||
imService.RegisterAdapterFactory("wechat", func(factoryCtx context.Context, channel *imPkg.IMChannel, msgHandler func(context.Context, *imPkg.IncomingMessage) error) (imPkg.Adapter, context.CancelFunc, error) {
|
||||
creds, err := parseCredentials(channel.Credentials)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("parse wechat credentials: %w", err)
|
||||
}
|
||||
|
||||
botToken := getString(creds, "bot_token")
|
||||
ilinkBotID := getString(creds, "ilink_bot_id")
|
||||
|
||||
if botToken == "" || ilinkBotID == "" {
|
||||
return nil, nil, fmt.Errorf("wechat credentials require bot_token and ilink_bot_id")
|
||||
}
|
||||
|
||||
adapter := wechat.NewAdapter(botToken, ilinkBotID)
|
||||
client := wechat.NewLongPollClient(botToken, ilinkBotID, msgHandler)
|
||||
|
||||
pollCtx, pollCancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
if err := client.Start(pollCtx); err != nil && pollCtx.Err() == nil {
|
||||
logger.Errorf(context.Background(), "[IM] WeChat long-poll stopped for channel %s: %v", channel.ID, err)
|
||||
}
|
||||
}()
|
||||
|
||||
return adapter, pollCancel, nil
|
||||
})
|
||||
|
||||
// Load and start all enabled channels from database
|
||||
if err := imService.LoadAndStartChannels(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user