calls.mjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. import { APIResource } from "../../core/resource.mjs";
  3. import { buildHeaders } from "../../internal/headers.mjs";
  4. import { path } from "../../internal/utils/path.mjs";
  5. export class Calls extends APIResource {
  6. /**
  7. * Accept an incoming SIP call and configure the realtime session that will handle
  8. * it.
  9. *
  10. * @example
  11. * ```ts
  12. * await client.realtime.calls.accept('call_id', {
  13. * type: 'realtime',
  14. * });
  15. * ```
  16. */
  17. accept(callID, body, options) {
  18. return this._client.post(path `/realtime/calls/${callID}/accept`, {
  19. body,
  20. ...options,
  21. headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
  22. });
  23. }
  24. /**
  25. * End an active Realtime API call, whether it was initiated over SIP or WebRTC.
  26. *
  27. * @example
  28. * ```ts
  29. * await client.realtime.calls.hangup('call_id');
  30. * ```
  31. */
  32. hangup(callID, options) {
  33. return this._client.post(path `/realtime/calls/${callID}/hangup`, {
  34. ...options,
  35. headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
  36. });
  37. }
  38. /**
  39. * Transfer an active SIP call to a new destination using the SIP REFER verb.
  40. *
  41. * @example
  42. * ```ts
  43. * await client.realtime.calls.refer('call_id', {
  44. * target_uri: 'tel:+14155550123',
  45. * });
  46. * ```
  47. */
  48. refer(callID, body, options) {
  49. return this._client.post(path `/realtime/calls/${callID}/refer`, {
  50. body,
  51. ...options,
  52. headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
  53. });
  54. }
  55. /**
  56. * Decline an incoming SIP call by returning a SIP status code to the caller.
  57. *
  58. * @example
  59. * ```ts
  60. * await client.realtime.calls.reject('call_id');
  61. * ```
  62. */
  63. reject(callID, body = {}, options) {
  64. return this._client.post(path `/realtime/calls/${callID}/reject`, {
  65. body,
  66. ...options,
  67. headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
  68. });
  69. }
  70. }
  71. //# sourceMappingURL=calls.mjs.map