Giter VIP home page Giter VIP logo

node-voice's Introduction

Bandwidth Node Voice SDK

Test

OS Node
Windows 2016 12, 14, 16
Windows 2019 12, 14, 16
Ubuntu 20.04 12, 14, 16
Ubuntu 22.04 12, 14, 16

Note: As of version 2.0.0, this package has been upgraded to TypeScript

Getting Started

Installation

npm install @bandwidth/voice

Initialize

import { CreateCallRequest, ApiError, ApiController, Client, Response, SpeakSentence } from '@bandwidth/voice';
const client = new Client({
    basicAuthUserName: "username",
    basicAuthPassword: "password"
});

const controller = new ApiController(client);
const accountId = "12345";

To use a custom environment

import { ApiController, Client, Environment } from '@bandwidth/voice';
const client = new Client({
    basicAuthUserName: "username",
    basicAuthPassword: "password",
    environment: Environment.Custom,
    baseUrl: 'https://custom.bandwidth.com'
});

const controller = new ApiController(client);
const accountId = "12345";

Create A Phone Call

var from = "+15554443333";
var to = "+15553334444";
var answerUrl = "https://sample.com";
var applicationId = "3-a-b-c";
var body = {
    from: from,
    to: to,
    answerUrl: answerUrl,
    applicationId: applicationId,
};

var createCallResponse = await controller.createCall(accountId, body);
console.log(createCallResponse.result.callId);

Create BXML

var speakSentence = new SpeakSentence({
    sentence: "test",
    voice: "susan",
    gender: "female",
    locale: "en_US",
});

var response = new Response(speakSentence);

console.log(response.toBxml());

Supported Node Versions

This package can be used with Node >= 10

Credentials

Information for credentials for this package can be found at https://dev.bandwidth.com/guides/accountCredentials.html

node-voice's People

Contributors

abaldwin-bandwidth avatar ajrice6713 avatar bpateldx avatar brianluisgomez avatar bw-mot avatar ckoegel avatar dependabot[bot] avatar hamermike avatar jchavez443 avatar jmulford-bw avatar noahg1 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-voice's Issues

Question: Callback URL Defaults

Hi all!

We're finally integrating voice into our application. In the dashboard, we're able to set our "Call initiated callback method" and "Call status callback method" for each voice application we create. These are also available in the admin API when creating apps programmatically.

However, when creating a new call, the API appears to error if we don't also provide these URLs to your API server!

Expected type: ‘Optional<Object<{from,to,callTimeout,callbackTimeout,answerUrl,answerFallbackUrl,username,password,fallbackUsername,fallbackPassword,answerMethod,answerFallbackMethod,disconnectUrl,disconnectMethod,tag,applicationId,obfuscatedTo,obfuscatedFrom}>>’
    at DefaultRequestBuilder.prepareArgs (/Users/ruthwu/Universe/app/node_modules/@bandwidth/voice/dist/voice.cjs.development.js:770:11)
    at ApiController.createCall (/Users/ruthwu/Universe/app/node_modules/@bandwidth/voice/dist/voice.cjs.development.js:1860:24)
    at POST (/Users/ruthwu/Universe/app/packages/@universe/api/dist/src/api/v1/calling/providers/bandwidth/call.js:219:50)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  errors: { body: [ [Object] ] }
}

Is this intended behavior? My hope would be the application can provide default webhook URLs, and you can either rely on default endpoints in the app (and not send them in every voice API call) or choose to override them per call if we do provide a value.

getCallRecordings returns callAsText instead of callAsStream by default

Description

I'm not sure it's a bug, but more of a usability issue.... From the customer:
We're trying to use the NodeJS SDK version 4.1.2 (from NPM "@bandwidth/voice": "^4.1.2") to download a recording. The credentials and recording information passed to the SDK are correct, as we've successfully downloaded it using cURL.

When we call the getDownloadCallRecording method, the data returned is a binary string. We tried to encode the string into a wav file, but something goes wrong in the process, as VLC can't play the resulting file, whereas it can play it normally when we download it with cURL.

We noticed that if we change the getDownloadCallRecording method to return a buffer instead of a string, return req.callAsStream(requestOptions) instead of return req.callAsText(requestOptions), we can also save the audio data to a file in a way VLC can play it.

Basically I think this should default to a stream for ease of use.

Environment Information

  • OS Version: ???
  • SDK Version: "@bandwidth/voice": "^4.1.2"
  • Environment: Node

Sample Code Snippet

Snippet provided above


### Stack Trace
<!-- Please provide the stack trace that shows the bug. -->
```shell
# Stack Trace

Expected Behavior

Default to a stream instead of text.

Suggested Fix

I'm not sure the fix, but the requistBuilder template for the SDK has the option for streaming, so I'm not sure how to set the default for that particular method seen here:

export interface RequestOptions {

[BUG] Calling getDownloadCallRecording tries to parse the response body as if it was JSON

Checklist

  • Have you provided a description of the bug?
  • Have you provided your Environment information?
  • Have you provided a sample code snippet?
  • Have you provided a stack trace?
  • Have you outlined the expected behavior?

Description

Calling getDownloadCallRecording tries to parse the response body as if it was JSON, resulting in the following error:

Error: Could not parse body as JSON.
Unexpected token R in JSON at position 0

The response contains RIFF/WAVE data, not JSON. I was able to build my own request using got and the response contains a body that starts with "RIFF [some non printable characters] WAVE". That's why the JSON parser complains about the R. It's the beginning of a wave file header, not JSON. Also, the response header "content-type" is "audio/vnd.wave".

Environment Information

  • OS Version: Ubuntu 18.04 on WSL 2, on Windows 10.
  • SDK Version: 4.1.1
  • Environment: NodeJS v14.19.0

Sample Code Snippet

The code is precisely the example provided in the documentation. I just added the input values (credentials, accountId, callId, and recordingId).

import { Client, ApiController } from '@bandwidth/voice'

const BW_USERNAME = "****";
const BW_PASSWORD = "****"
const BW_ACCOUNT_ID = "****";
const client = new Client({
    basicAuthUserName: BW_USERNAME,
    basicAuthPassword: BW_PASSWORD
})

const controller = new ApiController(client);
const accountId = BW_ACCOUNT_ID
const callId = '****';
const recordingId = '****';

try {
    const response = await controller.getDownloadCallRecording(accountId, callId, recordingId);
    console.log(response);
} catch (error) {
    console.error(error)
}

Stack Trace

Error: Could not parse body as JSON.

Unexpected token R in JSON at position 0
    at DefaultRequestBuilder.callAsJson (/home/posu/n2uitive/bandwidth-examples/node_modules/@bandwidth/voice/dist/voice.cjs.development.js:3150:13)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async file:///home/posu/n2uitive/bandwidth-examples/download-recording.js:17:22

Expected Behavior

The method returns a promise that resolves to audio data.

Suggested Fix

I didn't study the code enough to know for sure, but I suspect that line 307 of apiController.ts shouldn't be calling callAsJson on the request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.