-
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
f757134
commit 3c8b782
Showing
11 changed files
with
318 additions
and
44 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
examples/simple-examples/src/conversation/conversation/injectEvent.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,35 @@ | ||
import { InjectEventRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getContactIdFromConfig, | ||
getConversationIdFromConfig, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
|
||
(async () => { | ||
console.log('****************************'); | ||
console.log('* Conversation_InjectEvent *'); | ||
console.log('****************************'); | ||
|
||
const conversationId = getConversationIdFromConfig(); | ||
const contactId = getContactIdFromConfig(); | ||
|
||
const requestData: InjectEventRequestData= { | ||
conversation_id: conversationId, | ||
injectConversationEventRequestBody: { | ||
app_event: { | ||
composing_event: {}, | ||
}, | ||
accept_time: new Date(), | ||
conversation_id: conversationId, | ||
contact_id: contactId, | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.conversation.injectEvent(requestData); | ||
|
||
printFullResponse(response); | ||
|
||
})(); |
74 changes: 74 additions & 0 deletions
74
examples/simple-examples/src/conversation/conversation/listRecent.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,74 @@ | ||
import { | ||
ConversationRecentMessage, | ||
ListRecentConversationsRequestData, | ||
PageResult, | ||
} from '@sinch/sdk-core'; | ||
import { getAppIdFromConfig, getPrintFormat, initClient, printFullResponse } from '../../config'; | ||
|
||
const populateConversationsList = ( | ||
conversationPage: PageResult<ConversationRecentMessage>, | ||
conversationList: ConversationRecentMessage[], | ||
conversationDetailsList: string[], | ||
) => { | ||
conversationPage.data.map((recentConversation: ConversationRecentMessage) => { | ||
conversationList.push(recentConversation); | ||
conversationDetailsList.push(`${recentConversation.conversation?.id} - ${recentConversation.conversation?.active_channel}\n - Latest message: ${recentConversation.last_message?.accept_time}`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('****************************************'); | ||
console.log('* Conversation_ListRecentConversations *'); | ||
console.log('****************************************'); | ||
|
||
const appId = getAppIdFromConfig(); | ||
|
||
const requestData: ListRecentConversationsRequestData = { | ||
only_active: true, | ||
app_id: appId, | ||
order: 'ASC', | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await sinchClient.conversation.conversation.listRecent(requestData); | ||
|
||
const conversationList: ConversationRecentMessage[] = []; | ||
const conversationDetailsList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateConversationsList(response, conversationList, conversationDetailsList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(conversationDetailsList.length > 0 | ||
? 'List of conversations:\n' + conversationDetailsList.join('\n') | ||
: 'Sorry, no conversations were found.'); | ||
} else { | ||
printFullResponse(conversationList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const recentConversation of sinchClient.conversation.conversation.listRecent(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`${recentConversation.conversation?.id} - ${recentConversation.conversation?.active_channel}\n - Latest message: ${recentConversation.last_message?.accept_time}`); | ||
} else { | ||
console.log(recentConversation); | ||
} | ||
} | ||
|
||
})(); |
21 changes: 21 additions & 0 deletions
21
examples/simple-examples/src/conversation/events/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,21 @@ | ||
import { DeleteEventRequestData } from '@sinch/sdk-core'; | ||
import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; | ||
|
||
|
||
(async () => { | ||
console.log('**********************'); | ||
console.log('* Events_DeleteEvent *'); | ||
console.log('**********************'); | ||
|
||
const eventId = getEventIdFromConfig(); | ||
|
||
const requestData: DeleteEventRequestData = { | ||
event_id: eventId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.events.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,20 @@ | ||
import { GetEventRequestData } from '@sinch/sdk-core'; | ||
import { getEventIdFromConfig, initClient, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*******************'); | ||
console.log('* Events_GetEvent *'); | ||
console.log('*******************'); | ||
|
||
const eventId = getEventIdFromConfig(); | ||
|
||
const requestData: GetEventRequestData = { | ||
event_id: eventId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.events.get(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,76 @@ | ||
import { ConversationEvent, ListEventsRequestData, PageResult } from '@sinch/sdk-core'; | ||
import { | ||
getContactIdFromConfig, | ||
getConversationIdFromConfig, | ||
getPrintFormat, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
const populateEventsList = ( | ||
eventPage: PageResult<ConversationEvent>, | ||
eventList: ConversationEvent[], | ||
eventDetailsList: string[], | ||
) => { | ||
eventPage.data.map((event: ConversationEvent) => { | ||
eventList.push(event); | ||
eventDetailsList.push(`${event.id} - ${event.accept_time}`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('*********************'); | ||
console.log('* Events_ListEvents *'); | ||
console.log('*********************'); | ||
|
||
const contactId = getContactIdFromConfig(); | ||
const conversationId = getConversationIdFromConfig(); | ||
|
||
const requestData: ListEventsRequestData = { | ||
contact_id: contactId, | ||
conversation_id: conversationId, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await sinchClient.conversation.events.list(requestData); | ||
|
||
const eventsList: ConversationEvent[] = []; | ||
const eventsDetailsList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateEventsList(response, eventsList, eventsDetailsList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(eventsDetailsList.length > 0 | ||
? 'List of events:\n' + eventsDetailsList.join('\n') | ||
: 'Sorry, no events were found.'); | ||
} else { | ||
printFullResponse(eventsList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const event of sinchClient.conversation.events.list(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`${event.id} - ${event.accept_time}`); | ||
} else { | ||
console.log(event); | ||
} | ||
} | ||
|
||
})(); |
27 changes: 27 additions & 0 deletions
27
examples/simple-examples/src/conversation/messages/update.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 { UpdateMessageRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getMessageIdFromConfig, | ||
initClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('**************************'); | ||
console.log('* Messages_UpdateMessage *'); | ||
console.log('**************************'); | ||
|
||
const messageId = getMessageIdFromConfig(); | ||
|
||
const requestData: UpdateMessageRequestData = { | ||
message_id: messageId, | ||
updateMessageRequestBody: { | ||
metadata: 'Updated metadata', | ||
}, | ||
}; | ||
|
||
const sinchClient = initClient(); | ||
const response = await sinchClient.conversation.messages.update(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