Send a message
To send a message in a conversation, follow these steps:
- Extract the private key tied to the
m/0/0
path of your Twetch 12-word seed.
A JavaScript example can be found here.
- Fetch the encrypted key generated from Step 3 of Initiating a Chat.
HTTP POST request:
URL: https://api.twetch.app/v1/graphql
Headers: {
Authorization: ‘Bearer <twetch_authorization_token>’
}
Body: {
query: `{
conversationById(id: "${convId}") {
id
createdAt
me {
encryptedKey
}
}
}`
}
Response:
{
"data": {
conversationById: {
id: 'c5ef415a-5753-430d-a57c-dca1ff40a5e8',
createdAt: '2020-10-19T20:14:57.036066+02:00',
me: {
encryptedKey: 'QklFMQIvWga0Ndyv0ru8dL+W/Cvk6pAu9T9v79ARua7IGT2XGewBpmTIsViEG73yCSu9+lbOsdG/iWnLIy19if7PfUW2I2UaD9n8gaOb2ad/P5qnr3HUiJMpMDPwC4j+cxHbUmvGeAHEK4E3eyzLxthkNyB0'
}
}
}
}
- ECIES decrypt the encrypted key from Step 3.
A JavaScript example can be found here.
- AES encrypt the message being sent to the decrypted ECIES key from Step 3.
A JavaScript example can be found here.
- Create a JSON payload:
{
conversationId: <conversation_id>
userId: <from_user_id>
description: <encrypted_message_generated_in_Step_4>
}
- Post the payload from Step 5 to the
graphql
endpoint:
HTTP POST request:
URL: https://api.twetch.app/v1/graphql
Headers: {
Authorization: ‘Bearer <twetch_authorization_token>’
}
Body: {
query: `mutation createMessage($payload: MessageInput!) {
createMessage(input: { message: $payload }) {
message {
description
id
}
}
}`, { <payload_generated_in_Step_5> }
}
Response:
{
"data": {
createMessage: {
message: {
description: 'eeaaf4cd',
id: '1fb19cd0-8267-4070-b6f4-11e7dc31df35'
}
}
}
}