File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ) ) ;
You can’t perform that action at this time.
0 commit comments