Repository navigation
Add groundwork for emailing webchat visitors messages they didn't see - #5
Merged
Merged
Conversation
|
The groundwork is clear and well tested. I found three things worth fixing before the follow-up PR starts calling this code; details are in the inline comments:
Two test gaps:
|
…ame attachments from their decoded path
Member
Author
|
Added the tests the review asked for: escaping of sender names and attachment URLs (a |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
This is the groundwork for emailing webchat visitors the outgoing messages they didn't read in the chat. It adds the channel's email config, a Mailgun client and the email rendering. Nothing calls them yet, so behaviour doesn't change. A follow-up PR adds buffering of sent messages, a sweep that checks read status, and the actual sending.
Changes
core/models/channel.go:Channel.EmailConfig()reads the channel'semail_from,mailgun_domain,mailgun_regionandmailgun_api_keyconfig. It returns nil unless the from address, domain and key are all set to strings, because a channel with only some of them can't send.core/email/mailgun.go:Sendposts to Mailgun's/v3/{domain}/messageswith basic auth using the domain sending key."<name>" <email_from>and sets the channel UUID as a Mailgun user variable, so later events and webhooks can be matched to the channel.ErrUnsendablecovers emails that are never sent at all: an unknown region, or a recipient that isn't exactly one address. Mailgun accepts a list into, but a visitor's email must only reach them.SendError.IsRetryabletreats network errors, 429 and 5xx as worth retrying. Other 4xx errors and unsendable emails are permanent.core/email/render.go:Renderbuilds a multipart email (text and HTML from embedded templates) for a batch of messages.runtime/http.go: a separate HTTP client for Mailgun with a 30s timeout.web/internal.go:/wi/sendaccepts the contact's optionalemail. It isn't used yet and is never published to the chat. It's checked when sending rather than here, because rejecting the send would also fail the message for the chat.Example
For two unread messages, the text part looks like this:
The subject is
New message from <workspace>, orNew messages from <workspace>for more than one.Test plan
TestChannelEmailConfigcovers a complete config, each way it can be incomplete, and values that aren't stringsTestRendercovers:javascript:attachment URL neutralized in the HTMLTestSend(email) covers:TestSend(web) checks thatemailis accepted on/wi/sendand isn't publishedgo test ./...passes in the devcontainer