fix(dispatcher): avoid swallowing unmatched command handlers in whatsapp
This commit is contained in:
parent
09f467da8f
commit
e06ae83c22
5 changed files with 7 additions and 6 deletions
|
|
@ -280,5 +280,5 @@ func (c *WhatsAppChannel) tryHandleCommand(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.Matched
|
return res.Handled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ func TestTryHandleCommand_UsesDispatcher(t *testing.T) {
|
||||||
called := false
|
called := false
|
||||||
ch.dispatcher = commands.DispatchFunc(func(context.Context, commands.Request) commands.Result {
|
ch.dispatcher = commands.DispatchFunc(func(context.Context, commands.Request) commands.Result {
|
||||||
called = true
|
called = true
|
||||||
return commands.Result{Matched: true}
|
return commands.Result{Matched: true, Handled: true}
|
||||||
})
|
})
|
||||||
|
|
||||||
handled := ch.tryHandleCommand(context.Background(), "/help", "chat1", "user1", "mid1")
|
handled := ch.tryHandleCommand(context.Background(), "/help", "chat1", "user1", "mid1")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ func TestTryHandleCommand_UsesDispatcher(t *testing.T) {
|
||||||
called := false
|
called := false
|
||||||
ch.dispatcher = commands.DispatchFunc(func(context.Context, commands.Request) commands.Result {
|
ch.dispatcher = commands.DispatchFunc(func(context.Context, commands.Request) commands.Result {
|
||||||
called = true
|
called = true
|
||||||
return commands.Result{Matched: true}
|
return commands.Result{Matched: true, Handled: true}
|
||||||
})
|
})
|
||||||
|
|
||||||
handled := ch.tryHandleCommand(context.Background(), "/help", "chat1", "user1", "mid1")
|
handled := ch.tryHandleCommand(context.Background(), "/help", "chat1", "user1", "mid1")
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,7 @@ func (c *WhatsAppNativeChannel) tryHandleCommand(
|
||||||
"error": res.Err.Error(),
|
"error": res.Err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return res.Matched
|
return res.Handled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WhatsAppNativeChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
|
func (c *WhatsAppNativeChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ type Request struct {
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Matched bool
|
Matched bool
|
||||||
|
Handled bool
|
||||||
Command string
|
Command string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
@ -51,10 +52,10 @@ func (d *Dispatcher) Dispatch(ctx context.Context, req Request) Result {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if def.Handler == nil {
|
if def.Handler == nil {
|
||||||
return Result{Matched: true, Command: def.Name}
|
return Result{Matched: true, Handled: false, Command: def.Name}
|
||||||
}
|
}
|
||||||
err := def.Handler(ctx, req)
|
err := def.Handler(ctx, req)
|
||||||
return Result{Matched: true, Command: def.Name, Err: err}
|
return Result{Matched: true, Handled: true, Command: def.Name, Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result{Matched: false}
|
return Result{Matched: false}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue