Repository navigation
Let a bot open a direct conversation with a person - #50
Merged
Merged
Conversation
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.
Until now a bot could only write in conversations people opened with it. That rules out reminder, alert and notification bots that message one person. This PR lets a bot open a direct conversation itself, following Slack's model rather than Telegram's "the person writes first".
Rules
ChannelService/OpenDirectChannelwith a team and a person. Both must be members of that team. A bot can't open a group conversation (OpenGroupChannelstays off its allowlist, and the directory refuses it with code 3), and it can't open one with another bot (code 3).channels.ErrNotTaking). A deactivated or deleted account gets code 5, as for anyone else.services.directory.max_bot_conversations_per_hournew conversations an hour (30 by default). Past that the call returns code 8. Reopening a conversation that already exists is free, whoever opened it. Like the existing team and invite caps, the counter lives in the directory's memory.Bot,BotSeesAll), so it gets every message of the conversation, as with any direct conversation it's in. The person sees an ordinary direct conversation with the bot's badge. They can mute it, block the bot (which already stops its posts there) or delete it for themselves.Wiring
OpenDirectChannelto the bot allowlist (internal/server/drpc/middleware.go).openDirectmethod.Client.OpenDirect(ctx, teamID, userID).examples/echobot:/remindme 10m stand upsends the text back in a direct message when the time is up.docs/protocol.md: the bots' call table, a new "Writing to a person first" section, andopenDirectin the HTTP table. README updated too.DirectKeyHolderreads a conversation key, so the rate limit can let existing conversations through.A fix on the web side
The web tab only learned that a conversation was direct after its sidebar reloaded. A bot that opens a conversation and posts straight away could therefore beat that reload, and the person got no desktop notification for the first message. The session now marks a direct conversation as soon as
ChannelJoinedarrives.Pushes needed no change. The channel passes the person as a member, and
push/notify.goalready skips people who blocked the author. A new test covers this.Deploying
There's no migration and no proto change. The new config key has a default in
cmd/serve/default.yaml.Tests
openDirect(success, and 429 past the limit), an SDK test, and a web session test for the notification fix.test/e2e/bots_test.go): the bot opens a conversation with the admin and posts. The admin's sidebar shows it and a notification arrives. The admin's reply reaches the bot.OpenGroupChannelreturns code 12. While the admin blocks the bot,openDirectreturns 403 and the bot's post returns code 7. After unblocking,openDirectreturns the same conversation.Ran locally:
go test -race ./...and golangci-lint v2.15.0 (0 issues).Not run locally: e2e (left to CI) and the live Scylla test for
DirectKeyHolder, which skips withoutGOCHAT_TEST_SCYLLA. Docker already runs three Scylla nodes here, so I didn't start a throwaway one.