File tree 3 files changed +11
-3
lines changed
3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import type {
24
24
OnStatus ,
25
25
OnStatusArgs
26
26
} from "./emitters" ;
27
+ import { escapeUnicode } from "./utils" ;
27
28
28
29
/**
29
30
* The main API Class
@@ -730,7 +731,7 @@ export default class WhatsAppAPI {
730
731
[ "sign" , "verify" ]
731
732
) ;
732
733
733
- const data = encoder . encode ( raw_body ) ;
734
+ const data = encoder . encode ( escapeUnicode ( raw_body ) ) ;
734
735
const result = await this . subtle . sign ( "HMAC" , key , data . buffer ) ;
735
736
const result_array = Array . from ( new Uint8Array ( result ) ) ;
736
737
Original file line number Diff line number Diff line change @@ -4,6 +4,13 @@ export function isInteger(n: unknown): n is number {
4
4
return Number . isInteger ( n ) ;
5
5
}
6
6
7
+ export function escapeUnicode ( str : string ) {
8
+ // https://stackoverflow.com/a/40558081
9
+ return str . replace ( / [ ^ \0 - ~ ] / g, ( ch ) => {
10
+ return "\\u" + ( "000" + ch . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) ;
11
+ } ) ;
12
+ }
13
+
7
14
type Without < T , U > = { [ P in Exclude < keyof T , keyof U > ] ?: never } ;
8
15
export type XOR < T , U > = T | U extends object
9
16
? ( Without < T , U > & U ) | ( Without < U , T > & T )
Original file line number Diff line number Diff line change @@ -1520,9 +1520,9 @@ describe("WhatsAppAPI", function () {
1520
1520
const phoneID = "1" ;
1521
1521
const user = "2" ;
1522
1522
const body =
1523
- "Let's pretend this body is equal to the message object" ;
1523
+ "Let's pretend this body is equal to the message object and can handle unicode characters like みどりいろ and J'ai mangé des pâtes " ;
1524
1524
const signature =
1525
- "sha256=8d2c8fd74d3ac31eafd99563ac39107a45e5ea1d44831e291353193729d57f56 " ;
1525
+ "sha256=0363007aabdf1ab579f35936651a460fb5fa1aaf40df98b1264446b72cc96688 " ;
1526
1526
1527
1527
const name = "name" ;
1528
1528
const message = {
You can’t perform that action at this time.
0 commit comments