Skip to content

Commit 9fbd3a5

Browse files
Merge pull request #54 from TwilioDevEd/feature/rcs-support
feat: Add RCS message support
2 parents a50230f + 43ea1ee commit 9fbd3a5

54 files changed

Lines changed: 3539 additions & 2907 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ typings/
3535
# dotenv environment variables file
3636
.env
3737

38-
.DS_Store
38+
.DS_Store
39+
40+
# Context files (not for commits)
41+
.context/

README.md

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# SMS Segment Calculator
1+
# Messaging Segment Calculator (SMS + RCS)
22

3-
This repo contains a package for an SMS segments calculator. The package is released as a nodeJS package as well as a browser script.
3+
This repo contains a package for SMS and RCS segment calculations. The package is released as a nodeJS package as well as a browser script.
44
A browser demo for this package can be accessed [here](https://twiliodeved.github.io/message-segment-calculator/)
55

66
## Usage
@@ -13,32 +13,38 @@ The package can be installed using:
1313
npm install --save sms-segments-calculator
1414
```
1515

16-
Sample usage:
16+
Sample usage:
1717

1818
```javascript
19-
const { SegmentedMessage } = require('sms-segments-calculator');
19+
const { SegmentedMessage, RcsSegmentedMessage } = require('sms-segments-calculator');
2020

2121
const segmentedMessage = new SegmentedMessage('Hello World');
2222

2323
console.log(segmentedMessage.encodingName); // "GSM-7"
2424
console.log(segmentedMessage.segmentsCount); // "1"
25+
26+
const rcsMessage = new RcsSegmentedMessage('Hello RCS', 'us');
27+
console.log(rcsMessage.messageType); // "Rich"
28+
console.log(rcsMessage.segmentsCount); // "1"
2529
```
2630

2731
### Browser
2832

29-
You can add the library to your page using the CDN file:
33+
You can add the library to your page using the CDN file:
3034

3135
```html
32-
<script src="https://cdn.jsdelivr.net/gh/TwilioDevEd/message-segment-calculator/docs/scripts/segmentsCalculator.js" integrity="sha256-wXuHVlXNhEWNzRKozzB87Qyi9/3p6LKskjDXFHIMInw=" crossorigin="anonymous"></script>
36+
<script src="https://cdn.jsdelivr.net/gh/TwilioDevEd/message-segment-calculator/docs/scripts/segmentsCalculator.js" integrity="sha256-e2498331ca98c0d43952423be7ff75944f7f29d201da4ee466bd06e59e8054cb" crossorigin="anonymous"></script>
3337
```
3438

35-
Alternatively you can add the library to your page using the file [`segmentsCalculator.js`](https://github.com/TwilioDevEd/message-segment-calculator/blob/main/docs/scripts/segmentsCalculator.js) provided in `docs/scripts/` and adding it to your page:
39+
Alternatively you can add the library to your page using the file [`segmentsCalculator.js`](https://github.com/TwilioDevEd/message-segment-calculator/blob/main/docs/scripts/segmentsCalculator.js) provided in `docs/scripts/` and adding it to your page:
3640

3741
```html
3842
<script type="text/javascript" src="scripts/segmentsCalculator.js"></script>
3943
```
4044

41-
And example of usage can be find in [`docs/index.html`](https://github.com/TwilioDevEd/message-segment-calculator/blob/main/docs/index.html)
45+
Once loaded, the browser bundle exposes `SegmentedMessage` and `RcsSegmentedMessage` as globals.
46+
47+
An example of usage can be find in [`docs/index.html`](https://github.com/TwilioDevEd/message-segment-calculator/blob/main/docs/index.html)
4248

4349
## Documentation
4450
### `SegmentedMessage` class
@@ -70,12 +76,49 @@ Number of segment(s)
7076

7177
Return an array with the non GSM-7 characters in the body. It can be used to replace character and reduce the number of segments
7278

79+
### `RcsSegmentedMessage` class
80+
81+
RCS always uses UTF-8. For US destinations, messages are billed per 160 UTF-8 byte “Rich” segment. For international destinations, there is no segmentation: `<=160` bytes is billed as `Basic`, and `>160` bytes is billed as `Single`.
82+
83+
#### `constructor(message, region)`
84+
Arguments:
85+
* `message`: Body of the RCS message
86+
* `region`: `us` or `international` (default: `us`)
87+
88+
##### `encodingName`
89+
90+
Always returns `"UTF-8"`.
91+
92+
##### `numberOfBytes`
93+
94+
Number of UTF-8 bytes in the message body.
95+
96+
##### `messageSize`
97+
98+
Total size of the message body in bits.
99+
100+
##### `segmentsCount`
101+
102+
Number of RCS segment(s) the message is split into for billing.
103+
104+
##### `segments`
105+
106+
An array with one entry per segment. Each entry contains `index`, `capacity`, and `used` (bytes).
107+
108+
##### `messageType`
109+
110+
Returns `Rich`, `Basic`, or `Single` based on the region and UTF-8 length.
111+
112+
##### `region`
113+
114+
The region used for calculation: `"us"` or `"international"`.
115+
73116
## Try the library
74117

75118
If you want to test the library you can use the script provided in `playground/index.js`. Install the dependencies (`npm install`) and then run:
76119

77120
```shell
78-
$ node playground/index.js "👋 Hello World 🌍"
121+
node playground/index.js "👋 Hello World 🌍"
79122
```
80123

81124
## Contributing
@@ -89,6 +132,18 @@ The source code for the library is all contained in the `src` folder. Before sub
89132
* Execute the test using `npm test` and make sure all tests pass
90133
* Transpile the code using `npm run webpack` and test the web page in `docs/index.html`
91134

135+
## Accessibility
136+
137+
The docs UI follows Paste-aligned accessibility guidelines:
138+
* All color meaning includes a text label (encoding, fill state)
139+
* Stats updates use `aria-live="polite"` for screen reader announcements
140+
* Inputs include visible focus styles and associated labels
141+
* Segment bars use `role=\"meter\"` with value attributes
142+
143+
## Design Inspiration
144+
145+
We used the Kimoby SMS Segment Counter as visual inspiration: https://www.kimoby.com/calculators/sms-segment-counter
146+
92147
## License
93148

94149
[MIT](http://www.opensource.org/licenses/mit-license.html)

dist/browser/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

dist/browser/global.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/global.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/main.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

dist/browser/main.js

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/main.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/renderer.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { SmsAnalysis, RcsAnalysis } from './types';
2+
export interface SmsRenderTargets {
3+
encodingBadge: HTMLElement;
4+
encodingValue: HTMLElement;
5+
characters: HTMLElement;
6+
segments: HTMLElement;
7+
remaining: HTMLElement;
8+
segmentTape: HTMLElement;
9+
encodingSummary: HTMLElement;
10+
messageSize: HTMLElement;
11+
totalSize: HTMLElement;
12+
unicodeScalars: HTMLElement;
13+
nonGsmEmpty: HTMLElement;
14+
nonGsmTable: HTMLTableElement;
15+
nonGsmTableBody: HTMLElement;
16+
warnings: HTMLElement;
17+
error: HTMLElement;
18+
}
19+
export interface RcsRenderTargets {
20+
encodingBadge: HTMLElement;
21+
encodingValue: HTMLElement;
22+
characters: HTMLElement;
23+
segments: HTMLElement;
24+
messageType: HTMLElement;
25+
remaining: HTMLElement;
26+
size: HTMLElement;
27+
segmentTape: HTMLElement;
28+
detailsText: HTMLElement;
29+
detailSize: HTMLElement;
30+
detailBytes: HTMLElement;
31+
detailBilling: HTMLElement;
32+
charCount: HTMLElement;
33+
warning: HTMLElement;
34+
}
35+
export declare const renderSms: (analysis: SmsAnalysis, targets: SmsRenderTargets, errorMessage?: string) => void;
36+
export declare const renderRcs: (analysis: RcsAnalysis, targets: RcsRenderTargets) => void;

0 commit comments

Comments
 (0)