Skip to content

Commit ec5b6b8

Browse files
authored
feat(messages): added typing indicator support (#190)
1 parent 3164e3f commit ec5b6b8

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require('dotenv').config({ path: __dirname + '/../../.env' });
2+
3+
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID;
4+
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY;
5+
const MESSAGES_MESSAGE_ID = process.env.MESSAGES_MESSAGE_ID;
6+
const GEOSPECIFIC_MESSAGES_API_URL = process.env.GEOSPECIFIC_MESSAGES_API_URL;
7+
8+
const { Vonage } = require('@vonage/server-sdk');
9+
const { UpdateMessageStatus } = require('@vonage/messages');
10+
11+
/**
12+
* It is best to send messages using JWT instead of basic auth.
13+
*
14+
* @link https://developer.vonage.com/en/messages/technical-details#authentication
15+
*/
16+
const vonage = new Vonage(
17+
{
18+
applicationId: VONAGE_APPLICATION_ID,
19+
privateKey: VONAGE_PRIVATE_KEY,
20+
},
21+
{
22+
...(GEOSPECIFIC_MESSAGES_API_URL ? { apiHost: GEOSPECIFIC_MESSAGES_API_URL } : {}),
23+
},
24+
);
25+
26+
vonage.messages.updateMessage(
27+
MESSAGES_MESSAGE_ID,
28+
UpdateMessageStatus.READ,
29+
{
30+
typingIndicator: 'text',
31+
},
32+
)
33+
.then(({ messageUUID }) => console.log(messageUUID))
34+
.catch((error) => console.error(error));

0 commit comments

Comments
 (0)