Create a conversation
To initiate a Chat with Twetch users, follow these steps:
- Generate an AES cipher
A JavaScript example can be found here.
- Fetch the public key of each user in the Chat
HTTP POST request:
URL: https://api.twetch.app/v1/graphql
Headers: {
Authorization: ‘Bearer <twetch_authorization_token>’
}
Body: {
query: {
userById(id: "<Twetch_user_id>") {
publicKey
}
}
}
Response:
{
"data": {
"userById": {
"publicKey": "03344aeefe59c2546eefc1e61048f3c33cb75754581fcf3682c85c2c2fbfc7c9c6"
}
}
}
- ECIES encrypt the AES cipher generated in Step 1 to each public key generated in Step 2.
A JavaScript example can be found here.
- Create an array of users with the respective encrypted keys generated in Step 3 (including your user).
Example array:
[
{ userId: '145', encryptedKey: <ECIES_encrypted_cipher_to_145> },
{ userId: '17329', encryptedKey: <ECIES_encrypted_cipher_to_17329> }
]
- Make an HTTP POST request as follows to the
graphql
endpoint to create the conversation.
HTTP POST request:
URL: https://api.twetch.app/v1/graphql
Headers: {
Authorization: ‘Bearer <twetch_authorization_token>’
}
Body: {
query: `mutation createConversation($payload: String!) {
createConversation(input: { payload: $payload }) {
success
id
}
}`,
{ <array_generated_from_Step_4> }
}
Response:
{
"data": {
createConversation: {
success: true,
id: 'c5ef415a-5753-430d-a57c-dca1ff40a5e8'
}
}
}