mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-13 17:13:11 +01:00
Add option to send read receipt on confirmed delivery to WhatsApp
This commit is contained in:
parent
2857b57c8e
commit
c6b4f34c28
3 changed files with 19 additions and 0 deletions
|
@ -37,6 +37,7 @@ type BridgeConfig struct {
|
||||||
|
|
||||||
ConnectionTimeout int `yaml:"connection_timeout"`
|
ConnectionTimeout int `yaml:"connection_timeout"`
|
||||||
FetchMessageOnTimeout bool `yaml:"fetch_message_on_timeout"`
|
FetchMessageOnTimeout bool `yaml:"fetch_message_on_timeout"`
|
||||||
|
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
||||||
LoginQRRegenCount int `yaml:"login_qr_regen_count"`
|
LoginQRRegenCount int `yaml:"login_qr_regen_count"`
|
||||||
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
|
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
|
||||||
ConnectionRetryDelay int `yaml:"connection_retry_delay"`
|
ConnectionRetryDelay int `yaml:"connection_retry_delay"`
|
||||||
|
@ -81,6 +82,8 @@ type BridgeConfig struct {
|
||||||
|
|
||||||
func (bc *BridgeConfig) setDefaults() {
|
func (bc *BridgeConfig) setDefaults() {
|
||||||
bc.ConnectionTimeout = 20
|
bc.ConnectionTimeout = 20
|
||||||
|
bc.FetchMessageOnTimeout = false
|
||||||
|
bc.DeliveryReceipts = false
|
||||||
bc.LoginQRRegenCount = 2
|
bc.LoginQRRegenCount = 2
|
||||||
bc.MaxConnectionAttempts = 3
|
bc.MaxConnectionAttempts = 3
|
||||||
bc.ConnectionRetryDelay = -1
|
bc.ConnectionRetryDelay = -1
|
||||||
|
|
|
@ -77,6 +77,10 @@ bridge:
|
||||||
# to see if it was actually bridged? Use this if you have problems with sends timing out but actually
|
# to see if it was actually bridged? Use this if you have problems with sends timing out but actually
|
||||||
# succeeding.
|
# succeeding.
|
||||||
fetch_message_on_timeout: false
|
fetch_message_on_timeout: false
|
||||||
|
# Whether or not the bridge should send a read receipt from the bridge bot when a message has been
|
||||||
|
# sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will
|
||||||
|
# trigger a read receipt too.
|
||||||
|
delivery_receipts: false
|
||||||
# Number of times to regenerate QR code when logging in.
|
# Number of times to regenerate QR code when logging in.
|
||||||
# The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds)
|
# The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds)
|
||||||
login_qr_regen_count: 2
|
login_qr_regen_count: 2
|
||||||
|
|
12
portal.go
12
portal.go
|
@ -1436,6 +1436,15 @@ func (portal *Portal) sendErrorMessage(sendErr error) id.EventID {
|
||||||
return resp.EventID
|
return resp.EventID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
|
||||||
|
if portal.bridge.Config.Bridge.DeliveryReceipts {
|
||||||
|
err := portal.bridge.Bot.MarkRead(portal.MXID, eventID)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Debugfln("Failed to send delivery receipt for %s: %v", eventID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var timeout = errors.New("message sending timed out")
|
var timeout = errors.New("message sending timed out")
|
||||||
|
|
||||||
func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
||||||
|
@ -1459,6 +1468,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
||||||
case <-time.After(time.Duration(portal.bridge.Config.Bridge.ConnectionTimeout) * time.Second):
|
case <-time.After(time.Duration(portal.bridge.Config.Bridge.ConnectionTimeout) * time.Second):
|
||||||
if portal.bridge.Config.Bridge.FetchMessageOnTimeout && portal.wasMessageSent(sender, info.Key.GetId()) {
|
if portal.bridge.Config.Bridge.FetchMessageOnTimeout && portal.wasMessageSent(sender, info.Key.GetId()) {
|
||||||
portal.log.Debugln("Matrix event %s was bridged, but response didn't arrive within timeout")
|
portal.log.Debugln("Matrix event %s was bridged, but response didn't arrive within timeout")
|
||||||
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Warnfln("Response when bridging Matrix event %s is taking long to arrive", evt.ID)
|
portal.log.Warnfln("Response when bridging Matrix event %s is taking long to arrive", evt.ID)
|
||||||
errorEventID = portal.sendErrorMessage(timeout)
|
errorEventID = portal.sendErrorMessage(timeout)
|
||||||
|
@ -1470,6 +1480,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
||||||
portal.sendErrorMessage(err)
|
portal.sendErrorMessage(err)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
||||||
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
}
|
}
|
||||||
if errorEventID != "" {
|
if errorEventID != "" {
|
||||||
_, err = portal.MainIntent().RedactEvent(portal.MXID, errorEventID)
|
_, err = portal.MainIntent().RedactEvent(portal.MXID, errorEventID)
|
||||||
|
@ -1526,6 +1537,7 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
|
||||||
portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err)
|
portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Debugln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts)
|
portal.log.Debugln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts)
|
||||||
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue