-
Notifications
You must be signed in to change notification settings - Fork 1
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
DEVEXP-276: Add example files #15
Merged
asein-sinch
merged 1 commit into
DEVEXP-274_Conversation-API_Write-tests
from
DEVEXP-276_Conversation-API_Write-example-files
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
See comment related to SDK usage simplification (#13 (comment))