-
Notifications
You must be signed in to change notification settings - Fork 76
feat: added new mms examples #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
require('dotenv').config({ path: __dirname + '/../.env' }); | ||||||
|
||||||
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; | ||||||
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; | ||||||
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; | ||||||
const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; | ||||||
const MESSAGES_IMAGE_URL = process.env.MESSAGES_IMAGE_URL; | ||||||
const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL; | ||||||
const MESSAGES_API_URL = process.env.MESSAGES_API_URL; | ||||||
|
||||||
const { Channels, } = require('@vonage/messages'); | ||||||
const { Vonage } = require('@vonage/server-sdk'); | ||||||
|
||||||
/** | ||||||
* It is best to send messages using JWT instead of basic auth. If you leave out | ||||||
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens | ||||||
* | ||||||
* @link https://developer.vonage.com/en/messages/technical-details#authentication | ||||||
*/ | ||||||
const vonage = new Vonage( | ||||||
{ | ||||||
applicationId: VONAGE_APPLICATION_ID, | ||||||
privateKey: VONAGE_PRIVATE_KEY, | ||||||
}, | ||||||
{ | ||||||
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), | ||||||
}, | ||||||
); | ||||||
|
||||||
vonage.messages.send({ | ||||||
messageType: 'image', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
channel: Channels.MMS, | ||||||
content: [ | ||||||
{ | ||||||
type: 'image', | ||||||
url: MESSAGES_IMAGE_URL, | ||||||
}, | ||||||
{ | ||||||
type: 'file', | ||||||
url: MESSAGES_FILE_URL, | ||||||
|
||||||
} | ||||||
], | ||||||
to: MESSAGES_TO_NUMBER, | ||||||
from: MMS_SEENDER_ID, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
.then(({ messageUUID }) => console.log(messageUUID)) | ||||||
.catch((error) => console.error(error)); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||
require('dotenv').config({ path: __dirname + '/../.env' }); | ||||||
|
||||||
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; | ||||||
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; | ||||||
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; | ||||||
const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const MESSAGES_FILE_URL = process.env.MESSAGES_FILE_URL; | ||||||
const MESSAGES_API_URL = process.env.MESSAGES_API_URL; | ||||||
|
||||||
const { Vonage } = require('@vonage/server-sdk'); | ||||||
const { Channels } = require('@vonage/messages'); | ||||||
|
||||||
/** | ||||||
* It is best to send messages using JWT instead of basic auth. If you leave out | ||||||
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens | ||||||
* | ||||||
* @link https://developer.vonage.com/en/messages/technical-details#authentication | ||||||
*/ | ||||||
const vonage = new Vonage( | ||||||
{ | ||||||
applicationId: VONAGE_APPLICATION_ID, | ||||||
privateKey: VONAGE_PRIVATE_KEY, | ||||||
}, | ||||||
{ | ||||||
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), | ||||||
}, | ||||||
); | ||||||
|
||||||
vonage.messages.send({ | ||||||
messageType: 'image', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
channel: Channels.MMS, | ||||||
file: { | ||||||
url: MESSAGES_FILE_URL, | ||||||
}, | ||||||
to: MESSAGES_TO_NUMBER, | ||||||
from: MMS_SEENDER_ID, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
.then(({ messageUUID }) => console.log(messageUUID)) | ||||||
.catch((error) => console.error(error)); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||
require('dotenv').config({ path: __dirname + '/../.env' }); | ||||||
|
||||||
const VONAGE_APPLICATION_ID = process.env.VONAGE_APPLICATION_ID; | ||||||
const VONAGE_PRIVATE_KEY = process.env.VONAGE_PRIVATE_KEY; | ||||||
const MESSAGES_TO_NUMBER = process.env.MESSAGES_TO_NUMBER; | ||||||
const MMS_SEENDER_ID = process.env.MMS_SEENDER_ID; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const MESSAGES_API_URL = process.env.MESSAGES_API_URL; | ||||||
|
||||||
const { Vonage } = require('@vonage/server-sdk'); | ||||||
const { Channels } = require('@vonage/messages'); | ||||||
|
||||||
/** | ||||||
* It is best to send messages using JWT instead of basic auth. If you leave out | ||||||
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens | ||||||
* | ||||||
* @link https://developer.vonage.com/en/messages/technical-details#authentication | ||||||
*/ | ||||||
const vonage = new Vonage( | ||||||
{ | ||||||
applicationId: VONAGE_APPLICATION_ID, | ||||||
privateKey: VONAGE_PRIVATE_KEY, | ||||||
}, | ||||||
{ | ||||||
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}), | ||||||
}, | ||||||
); | ||||||
|
||||||
vonage.messages.send({ | ||||||
messageType: 'image', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
channel: Channels.MMS, | ||||||
text: 'This is an RCS text message sent via the Vonage Messages API.', | ||||||
to: MESSAGES_TO_NUMBER, | ||||||
from: MMS_SEENDER_ID, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
.then(({ messageUUID }) => console.log(messageUUID)) | ||||||
.catch((error) => console.error(error)); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.