github.com/status-im/status-go@v1.1.0/cmd/status-cli/README.md (about)

     1  # Status CLI
     2  
     3  The Status CLI is a command line interface for interacting with the Status messenging process. It is a tool for developers and QAs to test the communication workflow without running Status desktop and mobile app.
     4  
     5  ## Features
     6  
     7  - Create a new account
     8  - Send and receive contact request
     9  - DM between contacts
    10  
    11  ## Build
    12  
    13  Go to `cmd/status-cli` directory and build the binary
    14  
    15  ```bash
    16  go build
    17  ```
    18  
    19  You can also run `make status-cli` in the root directory to build the binary.
    20  
    21  ## Run
    22  
    23  ### Run `serve` command:
    24  
    25  ```bash
    26  # run alice's server
    27  ./status-cli serve
    28  
    29  # run charlie's server in another terminal with the logged pubkey of Alice
    30  ./status-cli serve -n charlie -p 8565 -a <alice-pubkey>
    31  ```
    32  
    33  You can send direct messages through JSON RPC. If you also want to send messages through terminal enable `interactive` mode (with the `-i` flag)
    34  
    35  JSON RPC examples:
    36  
    37  ```bash
    38  # get waku info
    39  curl -XPOST http://127.0.0.1:8545 -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"waku_info","params":[],"id":1}'
    40  
    41  # get peer info
    42  curl --request POST --url http://127.0.0.1:8545 --header 'Content-type: application/json' --data '{"jsonrpc": "2.0", "method": "wakuext_peers", "params": [], "id": 1}'
    43  
    44  # send contact request from charlie to alice (use -a flag will automatacally send contact request when starting)
    45  curl -XPOST http://127.0.0.1:8565 -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"wakuext_sendContactRequest","params":[{"id": "0x0436470da23039f10c1588bc6b9fcbd4b815bf9fae4dc09c0fb05a7eaaf1670b5dbdbc757630d54bf2f8be45a796304dc42506c3f4172f499f610a9ed85d9b0d4c", "message": "hello"}],"id":1}'
    46  
    47  # send dm from charlie to alice
    48  curl -XPOST http://127.0.0.1:8565 -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"wakuext_sendOneToOneMessage","params":[{"id": "0x0436470da23039f10c1588bc6b9fcbd4b815bf9fae4dc09c0fb05a7eaaf1670b5dbdbc757630d54bf2f8be45a796304dc42506c3f4172f499f610a9ed85d9b0d4c", "message": "how are you"}],"id":1}'
    49  
    50  # send dm from alice to charlie
    51  curl -XPOST http://127.0.0.1:8545 -H 'Content-type: application/json' -d '{"jsonrpc":"2.0","method":"wakuext_sendOneToOneMessage","params":[{"id": "0x042c0ce856c41ad6d3f651a84c83f646cdafdf3a26a3d69bce3a6ccf59b23b5a366c12162045d5066abad7912741a6e6c6e8e11e7826c4c850a1de7a2bae24a79c", "message": "Im fine, and you?"}],"id":1}'
    52  ```
    53  
    54  ### Run `serve-account` command
    55  
    56  The `./status-cli serve` command will generate a new account, it will print in the console the key UID of that account, if you want to re-run that created account (i.e.: run the account with the same public key), you can do so with this command:
    57  
    58  ```bash
    59  ./status-cli serve-account -n alice -kid 0x02887ff8dddb774ad836c00c8fd30ef9bc45d6b23f1f8cad1bff07d09cb378c3
    60  ```
    61  
    62  You will need the same name and key
    63  
    64  ### Run `simulate` command
    65  
    66  ```bash
    67  # simulate DM between two accounts
    68  ./status-cli simulate
    69  
    70  # simulate DM in a interactive way
    71  ./status-cli simulate -i
    72  
    73  # simulate DM with 3 messages
    74  ./status-cli simulate -c 3
    75  
    76  # run in light mode
    77  ./status-cli simulate --light
    78  ```
    79  
    80  You can run the commands with `--light` to work as a light client.
    81  
    82  Logs are recorded in file `*.log` and terminal.
    83  
    84  ## JSON-RPC use cases
    85  
    86  ### Start two CLIs adding each other as contacts
    87  
    88  ```bash
    89  # terminal 1 (alice)
    90  ./status-cli serve -n alice -p 5500
    91  # note the public key and the key id from the output
    92  
    93  # terminal 2 (bobby)
    94  ./status-cli serve -n bobby -p 5501 -a <alice_pub_key>
    95  ```
    96  
    97  ## Restart any existing account
    98  
    99  ```bash
   100  # notice we need both the name and the key id (not the pub key here)
   101  # the key id will be pressent in the logs when a new account is created, same as the public key
   102  ./status-cli serve -n bobby -kid <bob_key_id>
   103  ```
   104  
   105  ### Create community
   106  
   107  Have two CLIs running (`alice` and `bobby`)
   108  
   109  ```bash
   110  # 1. (alice) create community
   111  # this call will return the community id
   112  curl --request POST \
   113    --url http://127.0.0.1:5500/ \
   114    --header 'Content-type: application/json' \
   115    --data '{
   116   "jsonrpc": "2.0",
   117   "method": "wakuext_createCommunity",
   118   "params": [
   119    {
   120     "membership": 3,
   121     "name": "cli-test-1",
   122     "color": "#ffffff",
   123     "description": "cli-test-1"  
   124    }
   125   ],
   126   "id": 1
   127  }'
   128  
   129  # 2. (bobby & alice) fetch community (use communityId from step 1 response)
   130  curl --request POST \
   131    --url http://127.0.0.1:5501/ \
   132    --header 'Content-type: application/json' \
   133    --data '{
   134   "jsonrpc": "2.0",
   135   "method": "wakuext_fetchCommunity",
   136   "params": [
   137    {
   138     "communityKey": "0x02bea5af5779d5f742f2419cc0d819d3ce33adb922e8e90bdf3533fd121d52d4bc",
   139     "waitForResponse": true,
   140     "tryDatabase": true
   141    }
   142   ],
   143   "id": 1
   144  }'
   145  
   146  # 3. (bobby) request to join community (use communityId from step 1 response)
   147  # this call will return the requestsToJoinCommunity.id
   148  curl --request POST \
   149    --url http://127.0.0.1:5501/ \
   150    --header 'Content-type: application/json' \
   151    --data '{
   152   "jsonrpc": "2.0",
   153   "method": "wakuext_requestToJoinCommunity",
   154   "params": [
   155    {
   156     "communityId": "0x02bea5af5779d5f742f2419cc0d819d3ce33adb922e8e90bdf3533fd121d52d4bc"
   157    }
   158   ],
   159   "id": 1
   160  }'
   161  
   162  # 4. (alice) accept request to join community from bobby (use requestsToJoinCommunity.id from step 3 response)
   163  # in the response you can see the community id and the chats' ids for that community ($.result.communities[*].chats[*].id)
   164  curl --request POST \
   165    --url http://127.0.0.1:5500/ \
   166    --header 'Content-type: application/json' \
   167    --data '{
   168   "jsonrpc": "2.0",
   169   "method": "wakuext_acceptRequestToJoinCommunity",
   170   "params": [
   171    {
   172     "id": "0x1b828fe8c778403268ffcf80b892f8be46cf9a85ba2c9f479bfb0c0a807a71f4"
   173    }
   174   ],
   175   "id": 1
   176  }'
   177  
   178  # 5. (alice) send chat message (bobby should receive it)
   179  # chatId is the community id concatenated to the chat id (from step 4 response)
   180  curl --request POST \
   181    --url http://127.0.0.1:5500/ \
   182    --header 'Content-type: application/json' \
   183    --data '{
   184   "jsonrpc": "2.0",
   185   "method": "wakuext_sendChatMessage",
   186   "params": [
   187    {
   188     "chatId": "0x02bea5af5779d5f742f2419cc0d819d3ce33adb922e8e90bdf3533fd121d52d4bcdfe601d1-096c-4201-b692-fcdb81ef0cec",
   189     "text": "hello there",
   190     "contentType": 1
   191    }
   192   ],
   193   "id": 1
   194  }'
   195  
   196  # 6. (bobby) leave the community (use communityId from step 1 response)
   197  curl --request POST \
   198    --url http://127.0.0.1:5501/ \
   199    --header 'Content-type: application/json' \
   200    --data '{
   201   "jsonrpc": "2.0",
   202   "method": "wakuext_leaveCommunity",
   203   "params": [
   204    "0x02bea5af5779d5f742f2419cc0d819d3ce33adb922e8e90bdf3533fd121d52d4bc"
   205   ],
   206   "id": 1
   207  }'
   208  
   209  # Optional:
   210  # 7. (bobby & alice) fetch community again and verify the members (curl from step 2.)
   211  # 8. Instead of creating a community always you can restart alice and bobby and proceed from step 2. Alice is the owner
   212  
   213  ```
   214  
   215  ### Private group chat
   216  
   217  Have two CLIs running (`alice` and `bobby`)
   218  
   219  ```bash
   220  # 1. (alice) create the group chat including bobby's public key in it, 
   221  # the response will have the group chat id to send messages to it
   222  curl --request POST \
   223    --url http://127.0.0.1:8545/ \
   224    --header 'Content-type: application/json' \
   225    --data '{
   226   "jsonrpc": "2.0",
   227   "method": "wakuext_createGroupChatWithMembers",
   228   "params": [
   229    null,
   230    "group-chat-name",
   231    [
   232     "0x04d3c86dfc77b195b705e1831935066076018aa0d7c40044829801ebbfe9b06480ce4662072bf16a3ca7cb8f6289207614deceaf7d33e099dfc9281610375fec08"
   233    ]
   234   ],
   235   "id": 1
   236  }'
   237  
   238  # 2. (alice) send the message to the id of the group chat (from step 1 response)
   239  curl --request POST \
   240    --url http://127.0.0.1:5500/ \
   241    --header 'Content-type: application/json' \
   242    --data '{
   243   "jsonrpc": "2.0",
   244   "method": "wakuext_sendGroupChatMessage",
   245   "params": [
   246    {
   247     "id": "8291eae1-338c-4481-9997-04edd2d2bbed-0x0490cbce029eaf094c7f2dcf1feb2d60e91ab1498847eb29fa98cc5ea5a36666b3f9ada142f3080f5074abd942c863438f6af9475f30781790c7e36f9acd2ac93e",
   248     "message": "hello"
   249    }
   250   ],
   251   "id": 1
   252  }'
   253  ```