Branded IDs
A resource ID is astring at runtime, but the compiler treats it as a distinct type. This turns a mistake that would show up as a 404 in production into a compile error.
send() and the list methods return are already branded, so you only need to convert IDs that came from outside, such as one stored in your database.
toXId: convert without validating
toMessageId only casts. Use it when the value is already trusted, such as a field read from an API response or stored by you.
isXId: validate before you use
isMessageId checks the format (msg_ followed by 26 characters) and narrows the type. Use it for untrusted input, such as a URL parameter:
Available ID types
TemplateMediaId is different from MediaId: the first identifies the file of a template header, and the second, the media of a message. One is not assignable to the other. The Partner API IDs, such as PartnerProjectId (proj_) and ApiKeyId (key_), come from @routa-chat/sdk/partner.
For other prefixes, there are the generics Id<Prefix>, isPrefixedId and toId.
The
channel field of messages.send() and templates.submit() accepts a plain string. Resource IDs in retrieve, however, require the branded type. The two mediaId fields require it too: a TemplateMediaId in a templates.submit() header and a MediaId in the headerParameter of messages.send().Exported types
You can import the main types from the package:TemplateHeader, TemplateFooter, TemplateButton, TemplateComponents) keep the API’s snake_case (media_id, phone_number). The input types (TemplateHeaderInput and the other *Input types) use camelCase (mediaId, phoneNumber). See Templates.
Message content
MessageContent is a union discriminated by type. Narrow on that field. From version 0.2.0, message.content can also be null, when retention removed the content. Check for that before the switch:
Events
RoutaEvent is a union on type, with a last generic member for types your SDK version does not know yet. EventType has 17 members on 0.3.0 and every known event has externalRef. See Webhooks in the SDK.
Naming conventions
The SDK exposes the API fields in camelCase (deliveredAt, nextCursor), except in three places that keep the API format: message content (media_id, template_id, body_parameters, header_parameter, button_parameters), event data and the components of a template you read (media_id, phone_number).