22
33[ ![ Version] ( https://img.shields.io/npm/v/httpsms.svg )] ( https://www.npmjs.org/package/httpsms )
44[ ![ Build] ( https://github.com/NdoleStudio/httpsms-node/actions/workflows/main.yml/badge.svg )] ( https://github.com/NdoleStudio/httpsms-node/actions/workflows/main.yml )
5- [ ![ codecov] ( https://codecov.io/gh/NdoleStudio/httpsms-node/branch/main/graph/badge.svg )] ( https://codecov.io/gh/NdoleStudio/httpsms-node )
65[ ![ GitHub contributors] ( https://img.shields.io/github/contributors/NdoleStudio/httpsms-node )] ( https://github.com/NdoleStudio/httpsms-node/graphs/contributors )
76[ ![ GitHub license] ( https://img.shields.io/github/license/NdoleStudio/httpsms-node?color=brightgreen )] ( https://github.com/NdoleStudio/httpsms-node/blob/master/LICENSE )
87[ ![ Downloads] ( https://img.shields.io/npm/dm/httpsms.svg )] ( https://www.npmjs.com/package/httpsms )
@@ -14,74 +13,79 @@ This httpSMS library provides a server side javascript and typescript client for
1413``` sh
1514pnpm install httpsms-node
1615# or
17- npm install httpsms-node
18- # or
1916yarn install httpsms-node
2017```
2118
2219## Implemented
2320
24- - [x] ** [ MessageService ] ( #messages ) **
25- - [x] ` POST /v1/messages/send ` : Send a new SMS
26- - [x] ** Cipher**
27- - [x] ` Encrypt ` : Encrypt the content of a message to cipher text
28- - [x] ` Decrypt ` : Decrypt an encrypted message content to plain text
21+ - [x] ** [ Messages ] ( #messages ) **
22+ - [x] ` POST /v1/messages/send ` : Send a new SMS
23+ - [x] ** Cipher**
24+ - [x] ` Encrypt ` : Encrypt the content of a message to cipher text
25+ - [x] ` Decrypt ` : Decrypt an encrypted message content to plain text
2926
3027## Usage
3128
3229### Initializing the Client
3330
3431An instance of the client can be created using ` httpsms.New() ` .
3532
36- ``` go
37- package main
38-
39- import (
40- " github.com/NdoleStudio/httpsms-go"
41- )
33+ ``` js
34+ import HttpSms from " httpsms"
4235
43- func main () {
44- client := htpsms.New (htpsms.WithDelay (200 ))
45- }
36+ const client = new HttpSms (" " /* Get API Key from https://httpsms.com/settings */ );
4637```
4738
4839### Error handling
4940
50- All API calls return an ` error ` as the last return object. All successful calls will return a ` nil ` error .
41+ All API calls return a ` Promise<T> ` as the return object. You can handle the response in the ` then ` and ` catch ` methods .
5142
52- ``` go
53- _ , response , err := client.MessageService .Send (context.Background ())
54- if err != nil {
55- // handle error
56- }
57- ```
43+ ### Messages
5844
59- ### MessageService
45+ #### ` POST /v1/messages/send ` : Send an SMS Message
6046
61- #### ` POST /v1/messages/send ` : Send a new SMS Message
62-
63- ``` go
64- message , response , err := client.MessageService .Send (context.Background (), &MessageSendParams{
65- Content : " This is a sample text message" ,
66- From : " +18005550199" ,
67- To : " +18005550100" ,
47+ ``` js
48+ await client .messages .postSend ({
49+ content: ' This is a sample text message' ,
50+ from: ' +18005550199' ,
51+ to: ' +18005550100' ,
52+ })
53+ .then ((message ) => {
54+ console .log (message .id );
6855})
56+ .catch ((err ) => {
57+ console .error (err);
58+ });
59+ ```
60+
61+ ### Encrypt an SMS message before sending
6962
70- if err != nil {
71- log. Fatal (err)
72- }
63+ ``` js
64+ const encryptionKey = " Password123 " ;
65+ const encryptedContent = await client . cipher . encrypt ( " This is a sample text message " , encryptionKey);
7366
74- log.Println (message.Code ) // 202
67+ await client .messages .postSend ({
68+ content: encryptedContent,
69+ from: ' +18005550199' ,
70+ encrypted: true ,
71+ to: ' +18005550100' ,
72+ })
73+ .then ((message ) => {
74+ console .log (message .id );
75+ })
76+ .catch ((err ) => {
77+ console .error (err);
78+ });
7579```
7680
7781## Testing
7882
7983You can run the unit tests for this client from the root directory using the command below:
8084
8185``` bash
82- go tests -v
86+ pnpm run test
8387```
8488
8589## License
8690
87- This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details
91+ This project is licensed under the MIT License - see the [ LICENSE] ( license ) file for details
0 commit comments