Comments (5)
Hey there,
I'm closing this issue since it's related to our REST API and not directly to our React SDK. Feel free to reach out via live support on our site if you have any questions or comments regarding the REST API.
It's by design that you need to download and re-upload attachments in order to re import them, as documented in the importing section of our REST API
and then i will have to manually update the attachment token of the respected conversation with the token.
I Have like more than 150 conversation.
Since the data is returned in a standardized format, it should be fairly trivial to loop over the data or use our example data export script.
Also, they don't have way to identify which chat has a attachment until you export all the conversation.
You can fetch the conversations messages trough the api, which will show the attachments per message.
from talkjs-react.
Still the trival is not a proper solution. if i have mopre than 200 conversation and each conversation hold atleast 2 attachment.
do the math and calucate the labour work it has to be done.
no proper documentation
from talkjs-react.
Still the trival is not a proper solution. if i have mopre than 200 conversation and each conversation hold atleast 2 attachment. do the math and calucate the labour work it has to be done. no proper documentation
I'm definitely not suggesting to go over each conversation and message one by one by hand. But to iterate over them with code.
The export data script is a good starting point for this.
from talkjs-react.
But if still let say one conversation has 10 attachment.
i will have to download all that attachment manually and re-upload it.
then create a key Attachment Token and feed the token to it.
this is the case for just 1 conversation
what if i have 10 conversation with 10 attachment.
how would i do it then?
and by the way i checked my live data it has more than 200 conversation.
from talkjs-react.
As i previously mentioned, i would definitely not do this manually. Sine the API is designed to be called programmatically.
The way i would do it is:
- get all your conversations and messages using the API, iterate over the pages to get all data.
- for each conversation file, loop over the messages.
- if the message has no attachment: continue
- if the message has an attachment:
- download the attachment, all languages will have something build in to download a file
- re-upload the file to our API
- replace the attachment object with an attachment field and remove the text field
- use the import API to import your messages
If i remember correctly you are using PHP, in that case it would look something like:
$endpoint = "https://api.talkjs.com/v1/{$appId}/files";
// Function to upload file and get token
function uploadAndGetToken($filePath, $fileName, $endpoint) {
$cfile = new CURLFile($filePath, mime_content_type($filePath), $fileName);
$postData = ['file' => $cfile, 'filename' => $fileName];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
return null;
} else {
$responseArray = json_decode($response, true);
return $responseArray['attachmentToken'] ?? null;
}
}
foreach ($dataArray['messages'] as &$message) {
if (isset($message['attachment']['url'])) {
// Download the file
$fileUrl = $message['attachment']['url'];
$filePath = tempnam(sys_get_temp_dir(), 'upload');
file_put_contents($filePath, file_get_contents($fileUrl));
// Extract filename from URL
$fileName = basename(parse_url($fileUrl, PHP_URL_PATH));
// Upload the file and get the token
$token = uploadAndGetToken($filePath, $fileName, $endpoint);
if ($token) {
// Update the message with the attachmentToken
$message['attachmentToken'] = $token;
unset($message['text']);
unset($message['attachment']); // Remove the entire attachment field
}
// Clean up the temporary file
unlink($filePath);
}
}
file_put_contents('updated_messages.json', json_encode($dataArray, JSON_PRETTY_PRINT));
After which you can import updated_messages.
from talkjs-react.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from talkjs-react.