Repository navigation
💥 replace the communication layer with larkify - #178
Merged
Merged
Conversation
Tokens, HTTP, webhook verification and the long connection now come from larkify, following the approach of adapter-github. The events, messages and Bot methods stay as they are.
Covers the driver requirements, calling the API and what changes coming from 2.x.
Contributor
|
🚀 Deployed to https://deploy-preview-178--adapter-feishu.netlify.app |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #178 +/- ##
==========================================
+ Coverage 83.82% 87.50% +3.68%
==========================================
Files 15 11 -4
Lines 1719 1497 -222
==========================================
- Hits 1441 1310 -131
+ Misses 278 187 -91
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the hand-written HTTP, token, webhook and WebSocket code with larkify, a typed Feishu / Lark SDK built on httpx2 and pydantic. This follows the way adapter-github builds on githubkit. Events, messages, and the existing
Botmethods are unchanged.This is a breaking change and is released as 3.0.0. The new migration guide covers it for users.
Changes
Communication layer
Bot.feishuis a larkify client, created on first use so that aBotcan still be built with a fake adapter in plugin tests.DispatcheroverridesEventDispatcher.adispatch, so webhooks and the long connection share one entry point. larkify handles URL verification, decryption, signatures, and acknowledgements. Events still go throughjson_to_event.nonebot.adapters.feishu.wsis removed, along withframe_pb2.Adapter.startuprunslarkify.ws.WSClientinstead.larkifylogs now go throughLoguruHandler, soLOG_LEVELand loguru sinks apply to them.tenant_access_token/internal. Moving to the newer OAuth endpoint can happen separately, once it has been tried on a real app.New:
bot.restAs in adapter-github, these calls go through
call_api, soon_calling_apiandon_called_apistill run. One difference: positional arguments work here. The path parameters of the generated methods can be positional, so a keyword-only proxy would pass type checking and then fail at runtime.bot.call_api("im/v1/messages", method="GET", ...)keeps working and returns the same shape.Breaking changes
NetworkErrorActionFailedcodeActionFailedNetworkErrorActionFailedActionFailedwas documented onBot.call_apibut never raised. Rate-limited requests and server errors on idempotent requests are now retried automatically. POST requests are not retried after a server error, so a message cannot be sent twice.send_request,get_api_url,get_tenant_access_token,AESCipher,cache, andTenantAccessTokenResponseare removed.Behavior that stays the same
http://api_basestill works, throughinsecure_allow_http. The defaults are https, so http can only come from explicit configuration.API_TIMEOUT=nullstill means no timeout, and_timeoutstill applies per call.header, which means event v1, still get a 400.Dependencies
protobuf,cashews, andpycryptodomeare replaced bylarkify[crypto,ws]andhttpx2. A forward driver is no longer needed: webhooks need an ASGI driver, and bots that only use the long connection can run onDRIVER=~none.Testing
pytest: 102 passed on Python 3.11 and 3.15, also from a clean export with the locked dependencies. The test driver is now~fastapialone.tests/test_feishu_ws.pyis rewritten, because the old tests covered the removed internals. Events now travel over a real socket toBot.handle_event.tests/test_feishu_api.pycoverscall_apiandbot.rest.nonebot.run()on~noneagainst a local fake Feishu: a long connection event reached a matcher, andbot.sendcalled the API with a token.pnpm build,scripts/build_api_docs.py, and Ruff pass. Pyright reports nothing new innonebot/.Not tested against real Feishu. Everything above uses local fake servers. Before releasing, please try one app on each of these:
Release notes
:bookmark: release 3.0.0only sets the version. Pruningwebsite/versioned_docsand running the Release workflow are left for release time.release-drafter.ymlrefers toBreakingandmajorlabels, but neither exists in this repository, so this PR is labeledenhancement. The tag comes frompyproject.toml, so the version is not affected.