Skip to content

Commit

Permalink
Messaging "send()" return types (#516)
Browse files Browse the repository at this point in the history
* add Messaging "send" return types

* add types
  • Loading branch information
edolix authored Apr 29, 2022
1 parent 6ebf3f6 commit 484d7fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-snakes-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/realtime-api': patch
---

Add `Messaging.send()` return types
18 changes: 15 additions & 3 deletions packages/realtime-api/src/messaging/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ interface InternalMessagingSendParams
to_number: string
}

interface MessagingSendResult {
message: string
code: string
messageId: string
}

interface MessagingSendError {
message: string
code: string
errors: Record<any, any>
}

/** @internal */
export interface Messaging
extends DisconnectableClientContract<Messaging, MessagingClientApiEvents> {
/** @internal */
_session: RealtimeClient
send(params: MessagingSendParams): Promise<any>
send(params: MessagingSendParams): Promise<MessagingSendResult>
}

/** @internal */
Expand Down Expand Up @@ -101,10 +113,10 @@ class MessagingAPI extends BaseComponent<MessagingClientApiEvents> {
params: sendParams,
})

return toExternalJSON(response)
return toExternalJSON<MessagingSendResult>(response)
} catch (error) {
this.logger.error('Error sending message', error.jsonrpc)
throw error.jsonrpc
throw error.jsonrpc as MessagingSendError
}
}
}
Expand Down

0 comments on commit 484d7fc

Please sign in to comment.