News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Request to create custom user greeting returns socket hang up error
Tags: rest api, custom greeting
Aug 15, 2022 at 8:20am   •   1 replies  •  0 likes
Kamron Clark

I am attempting to migrate the part of my app for creating a custom user greeting from using a local file to using a file publicly hosted online. Here is my current code:


async function create_greeting() {
  try {
    let FormData = require('form-data');
    formData = new FormData();
    let body = {
        type: "Introductory",
        answeringRule: {id: "3839201036"}
    }
 
    formData.append('json', new Buffer.from(JSON.stringify(body)), {
          filename: 'request.json',
          contentType: 'application/json'
          });
 
    formData.append('binary', fs.createReadStream('URL_to_file'));
    let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData);
    let jsonObj = await resp.json()
      .then(() => console.log(JSON.stringify(jsonObj)));
  } catch(e) {
    console.log(e.message)
  }
}

When I changed the file reference on line 15 from a local file path to a public URL I got the following response: "request to https://platform.ringcentral.com/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true failed, reason: socket hang up". How do I change the function to use a web-hosted file? Language is Node.js and I am using Google Cloud Storage to host the file.

1 Answer
answered on Aug 15, 2022 at 12:20pm  

Google does not allow accessing its Cloud Storage that way. Ask Google support or search on the stack overflow such as this one to learn how to download or read to a stream.

https://stackoverflow.com/questions/71097537/how-to-download-file-from-google-cloud-storage


 0
on Aug 16, 2022 at 7:19am   •  0 likes

After referencing that article and the Google Cloud Storage documentation I can't get the create greeting endpoint to accept the data downloaded into memory. For the purposes of this app, downloading to a file is not an option. Here is my current code:

  
  1. async function downloadIntoMemory() {
  2. // Downloads the file into a buffer in memory.
  3. const contents = await storage.bucket(bucketName).file(destFileName).download();
  4.  
  5. console.log(
  6. `Contents have been downloaded`
  7. );
  8.  
  9. //console.log(Buffer.from(contents.toString()).toString());
  10. create_greeting(contents.toString('binary'));
  11. }
  12.  
  13. async function create_greeting(data) {
  14. try {
  15. let FormData = require('form-data');
  16. formData = new FormData();
  17. let body = {
  18. type: "Introductory",
  19. answeringRule: { id: "3839201036"}
  20. }
  21. formData.append('json', new Buffer.from(JSON.stringify(body)), {
  22. filename: 'request.json',
  23. contentType: 'application/json'
  24. });
  25. formData.append('binary', fs.createReadStream(data));
  26. let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData);
  27. let jsonObj = await resp.json()
  28. .then(() => console.log(JSON.stringify(jsonObj)));
  29. } catch(e) {
  30. console.log(e.message)
  31. }
  32. }
  33.  
  34. downloadIntoMemory().catch(console.error);

When I run this code I get the error: "The argument 'path' must be a string or Uint8Array without null bytes". How can I change the data buffer from the Cloud Storage download into an acceptable format?

on Aug 16, 2022 at 10:30am   •  0 likes

I am not an expert on GC and I don't have an account to try it. But this may help

https://stackoverflow.com/questions/28256033/load-a-gcloud-createreadstream-into-a-variable-in-nodejs

on Aug 16, 2022 at 12:08pm   •  0 likes

Is it possible to pass raw data into the request for the "binary" parameter? I've tried passing the audio as a Buffer, arrayBuffer, base64 string, Blob, and Blob string and none of them have worked. Almost all of them fail with the message "Invalid attachment media type". How come using the CreateReadStream() method on a local file works for passing the audio, but passing the binary of that file doesn't?

on Aug 31, 2022 at 2:43pm   •  0 likes

After referencing that article and the Google Cloud Storage documentation I can't get the create greeting endpoint to accept the data downloaded into memory. For the purposes of this app, downloading to a file is not an option. Here is my current code:

  
  1. async function downloadIntoMemory() {
  2. // Downloads the file into a buffer in memory.
  3. const contents = await storage.bucket(bucketName).file(destFileName).download();
  4.  
  5. console.log(
  6. `Contents have been downloaded`
  7. );
  8.  
  9. //console.log(Buffer.from(contents.toString()).toString());
  10. create_greeting(contents.toString('binary'));
  11. }
  12.  
  13. async function create_greeting(data) {
  14. try {
  15. let FormData = require('form-data');
  16. formData = new FormData();
  17. let body = {
  18. type: "Introductory",
  19. answeringRule: { id: "3839201036"}
  20. }
  21. formData.append('json', new Buffer.from(JSON.stringify(body)), {
  22. filename: 'request.json',
  23. contentType: 'application/json'
  24. });
  25. formData.append('binary', fs.createReadStream(data));
  26. let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData);
  27. let jsonObj = await resp.json()
  28. .then(() => console.log(JSON.stringify(jsonObj)));
  29. } catch(e) {
  30. console.log(e.message)
  31. }
  32. }
  33.  
  34. downloadIntoMemory().catch(console.error);

When I run this code I get the error: "The argument 'path' must be a string or Uint8Array without null bytes. Received 'ID3\x04\x00\x00\x00\x00\x00\x1CTSSE\x00\x00\x00\b\x00\x00\x03Google\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00D\x00\x00\x00...". How can I change the data buffer from the Cloud Storage download into an acceptable format?

on Aug 15, 2022 at 1:28pm   •  0 likes

After referencing that article and the Google Cloud Storage documentation I can't get the create greeting endpoint to accept the data downloaded into memory. For the purposes of this app, downloading to a file is not an option. Here is my current code:

async function downloadIntoMemory() {
  // Downloads the file into a buffer in memory.
  const contents = await storage.bucket(bucketName).file(destFileName).download();

  console.log(
    `Contents have been downloaded`
  );

  //console.log(Buffer.from(contents.toString()).toString());
  create_greeting(contents.toString('binary'));
}

async function create_greeting(data) {
    try {
      let FormData = require('form-data');
      formData = new FormData();
      let body = {
          type: "Introductory",
          answeringRule: {id: "3839201036"}
      }
   
      formData.append('json', new Buffer.from(JSON.stringify(body)), {
            filename: 'request.json',
            contentType: 'application/json'
            });
   
      formData.append('binary', fs.createReadStream(data));
      let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData);
      let jsonObj = await resp.json()
        .then(() => console.log(JSON.stringify(jsonObj)));
    } catch(e) {
      console.log(e.message)
    }
  }

downloadIntoMemory().catch(console.error);

When I run this code I get the error: "The argument 'path' must be a string or Uint8Array without null bytes. Received 'ID3\x04\x00\x00\x00\x00\x00\x1CTSSE\x00\x00\x00\b\x00\x00\x03Google\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00D\x00\x00\x00...". How can I change the data buffer from the Cloud Storage download into an acceptable format?

on Aug 31, 2022 at 2:43pm   •  0 likes

After reviewing the article and the Google Cloud Storage documentation, I can't get the FormData to accept the data downloaded into a buffer. I've tried the raw buffer data, converting to string, converting to binary, and I can't get it to accept the data format. For the purposes of this app, downloading to a file is not an option. Here is my current code:


async function downloadIntoMemory() {
  // Downloads the file into a buffer in memory.
  const contents = await storage.bucket(bucketName).file(destFileName).download();

  console.log(
    `Contents have been downloaded`
  );

  //console.log(Buffer.from(contents.toString()).toString());
  create_greeting(contents.toString('binary'));
}

async function create_greeting(data) {
    try {
      let FormData = require('form-data');
      formData = new FormData();
      let body = {
          type: "Introductory",
          answeringRule: {id: "3839201036"}
      }
   
      formData.append('json', new Buffer.from(JSON.stringify(body)), {
            filename: 'request.json',
            contentType: 'application/json'
            });
   
      formData.append('binary', data);
      let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData);
      let jsonObj = await resp.json()
        .then(() => console.log(JSON.stringify(jsonObj)));
    } catch(e) {
      console.log(e.message)
    }
}


When I run this code, I get the error: "Invalid attachment media type". When I run the code but with fs.createReadStream(data) instead, I get this error: "The argument 'path' must be a string or Uint8Array without null bytes. Received 'ID3\x04\x00\x00\x00\x00\x00\x1CTSSE\x00\x00\x00\b\x00\x00\x03Google\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00D\x00\x00\x00...". How can I get it to accept the data type without creating a file?



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us