-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faca3fe
commit 22cda81
Showing
37 changed files
with
1,265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { CreateAppRequestData } from '@sinch/sdk-core'; | ||
import { getMessengerTokenFormConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*****************'); | ||
console.log('* App_CreateApp *'); | ||
console.log('*****************'); | ||
|
||
const messengerToken = getMessengerTokenFormConfig(); | ||
|
||
const requestData: CreateAppRequestData = { | ||
appCreateRequestBody: { | ||
display_name: 'New app created with the Node.js SDK', | ||
channel_credentials: [ | ||
{ | ||
channel: 'MESSENGER', | ||
static_token: { | ||
token: messengerToken, | ||
}, | ||
}, | ||
], | ||
conversation_metadata_report_view: 'FULL', | ||
retention_policy: { | ||
retention_type: 'CONVERSATION_EXPIRE_POLICY', | ||
ttl_days: 60, | ||
}, | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.app.create(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`New app created with the id '${response.id}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
console.log(`You may want to update your .env file with the following value: CONVERSATION_APP_ID=${response.id}`); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DeleteAppRequestData } from '@sinch/sdk-core'; | ||
import { getAppIdFromConfig, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*****************'); | ||
console.log('* App_DeleteApp *'); | ||
console.log('*****************'); | ||
|
||
const appId = getAppIdFromConfig(); | ||
|
||
const requestData: DeleteAppRequestData = { | ||
app_id: appId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.app.delete(requestData); | ||
|
||
printFullResponse(response); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { GetAppRequestData } from '@sinch/sdk-core'; | ||
import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('**************'); | ||
console.log('* App_GetApp *'); | ||
console.log('**************'); | ||
|
||
const appId = getAppIdFromConfig(); | ||
|
||
const requestData: GetAppRequestData = { | ||
app_id: appId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.app.get(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The app with the id '${response.id}' is named '${response.display_name}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ListAppsRequestData } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('****************'); | ||
console.log('* App_ListApps *'); | ||
console.log('****************'); | ||
|
||
const requestData: ListAppsRequestData= {}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.app.list(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(response.apps | ||
? response.apps.map((app) => `'${app.id}': ${app.display_name}`).join('\n') | ||
: 'No Conversation Applications were found'); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { UpdateAppRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getAppIdFromConfig, getMessengerTokenFormConfig, | ||
getPrintFormat, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*****************'); | ||
console.log('* App_UpdateApp *'); | ||
console.log('*****************'); | ||
|
||
const appId = getAppIdFromConfig(); | ||
|
||
const requestData: UpdateAppRequestData = { | ||
app_id: appId, | ||
update_mask: ['display_name', 'conversation_metadata_report_view'], | ||
appUpdateRequestBody: { | ||
display_name: 'Updated name by the Node.js SDK', | ||
conversation_metadata_report_view: 'NONE', | ||
channel_credentials: [ | ||
{ | ||
channel: 'MESSENGER', | ||
static_token: { | ||
token: 'new token (invalid) - should not be updated thanks to the mask', | ||
}, | ||
}, | ||
], | ||
|
||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.app.update(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`App updated! New name: '${response.display_name}'.`); | ||
const token = getMessengerTokenFormConfig(); | ||
console.log(`Verifying the token (it should be unchanged):\nOLD: '${token}'\nNEW: '${response.channel_credentials?.[0].static_token?.token}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
27 changes: 27 additions & 0 deletions
27
examples/simple-examples/src/conversation/capability/lookup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { LookupCapabilityRequestData } from '@sinch/sdk-core'; | ||
import { getAppIdFromConfig, getContactIdFromConfig, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('******************************'); | ||
console.log('* Capability_QueryCapability *'); | ||
console.log('******************************'); | ||
|
||
const appId = getAppIdFromConfig(); | ||
const contactId = getContactIdFromConfig(); | ||
|
||
const requestData: LookupCapabilityRequestData = { | ||
lookupCapabilityRequestBody: { | ||
app_id: appId, | ||
recipient: { | ||
contact_id: contactId, | ||
}, | ||
request_id: 'myPersonalId_' + new Date().getTime(), | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.capability.lookup(requestData); | ||
|
||
printFullResponse(response); | ||
|
||
})(); |
50 changes: 50 additions & 0 deletions
50
examples/simple-examples/src/conversation/contact/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { CreateContactRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getAppIdFromConfig, | ||
getMessengerUserIdFromConfig, | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*************************'); | ||
console.log('* Contact_CreateContact *'); | ||
console.log('*************************'); | ||
|
||
const phoneNumber = getPhoneNumberFromConfig(); | ||
const messengerUserId = getMessengerUserIdFromConfig(); | ||
const appId = getAppIdFromConfig(); | ||
|
||
const requestData: CreateContactRequestData = { | ||
contactCreateRequestBody: { | ||
display_name: 'New contact created with the Node.js SDK', | ||
channel_identities: [ | ||
{ | ||
identity: messengerUserId, | ||
channel: 'MESSENGER', | ||
app_id:appId, | ||
}, | ||
{ | ||
identity: phoneNumber, | ||
channel: 'WHATSAPP', | ||
}, | ||
], | ||
channel_priority: ['WHATSAPP'], | ||
language: 'EN_US', | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.contact.create(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`New contact created with the id '${response.id}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
20 changes: 20 additions & 0 deletions
20
examples/simple-examples/src/conversation/contact/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DeleteContactRequestData } from '@sinch/sdk-core'; | ||
import { getContactIdFromConfig, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*************************'); | ||
console.log('* Contact_DeleteContact *'); | ||
console.log('*************************'); | ||
|
||
const contactId = getContactIdFromConfig(); | ||
|
||
const requestData: DeleteContactRequestData = { | ||
contact_id: contactId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.contact.delete(requestData); | ||
|
||
printFullResponse(response); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { GetContactRequestData } from '@sinch/sdk-core'; | ||
import { getContactIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('**********************'); | ||
console.log('* Contact_GetContact *'); | ||
console.log('**********************'); | ||
|
||
const contactId = getContactIdFromConfig(); | ||
|
||
const requestData: GetContactRequestData = { | ||
contact_id: contactId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.contact.get(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The contact with the id '${response.id}' is named '${response.display_name}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
Oops, something went wrong.