Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to get a connection from the task #754

Closed
vtrofin opened this issue Sep 25, 2023 · 1 comment
Closed

Failure to get a connection from the task #754

vtrofin opened this issue Sep 25, 2023 · 1 comment

Comments

@vtrofin
Copy link

vtrofin commented Sep 25, 2023

Hi team,

I'm implementing a Custom CCP Panel. I'm trying to End a task by using the connection destroy API. However, I can't retrieve the connection from the task, I get the following error:

connect-streams.js:30338 Uncaught TypeError: Cannot read properties of undefined (reading 'create')
    at createMediaInstance (connect-streams.js:30338:44)
    at Object.get (connect-streams.js:30403:16)
    at getMediaController (connect-streams.js:30213:115)
    at Object.get (connect-streams.js:30231:16)
    at Connection._initMediaController (connect-streams.js:1446:33)
    at TaskConnection.Connection (connect-streams.js:1331:10)
    at new TaskConnection (connect-streams.js:2399:16)
    at connect-streams.js:1013:16
    at Array.map (<anonymous>)
    at Contact.getConnections (connect-streams.js:1009:40)
createMediaInstance @ connect-streams.js:30338
get @ connect-streams.js:30403
getMediaController @ connect-streams.js:30213
get @ connect-streams.js:30231
Connection._initMediaController @ connect-streams.js:1446
Connection @ connect-streams.js:1331
TaskConnection @ connect-streams.js:2399
(anonymous) @ connect-streams.js:1013
Contact.getConnections @ connect-streams.js:1009
endTask @ hook.ts:153
callCallback2 @ react-dom.development.js:4164
invokeGuardedCallbackDev @ react-dom.development.js:4213
invokeGuardedCallback @ react-dom.development.js:4277
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4291
executeDispatch @ react-dom.development.js:9041
processDispatchQueueItemsInOrder @ react-dom.development.js:9073
processDispatchQueue @ react-dom.development.js:9086
dispatchEventsForPlugins @ react-dom.development.js:9097
(anonymous) @ react-dom.development.js:9288
batchedUpdates$1 @ react-dom.development.js:26140
batchedUpdates @ react-dom.development.js:3991
dispatchEventForPluginEventSystem @ react-dom.development.js:9287
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay @ react-dom.development.js:6465
dispatchEvent @ react-dom.development.js:6457
dispatchDiscreteEvent @ react-dom.development.js:6430
Show 24 more frames
Show less
react-dom.development.js:4312 Uncaught TypeError: Cannot read properties of undefined (reading 'create')
    at createMediaInstance (connect-streams.js:30338:44)
    at Object.get (connect-streams.js:30403:16)
    at getMediaController (connect-streams.js:30213:115)
    at Object.get (connect-streams.js:30231:16)
    at Connection._initMediaController (connect-streams.js:1446:33)
    at TaskConnection.Connection (connect-streams.js:1331:10)
    at new TaskConnection (connect-streams.js:2399:16)
    at connect-streams.js:1013:16
    at Array.map (<anonymous>)
    at Contact.getConnections (connect-streams.js:1009:40)

Here is my implementation in React:

const getCurrentTask = (): connect.Contact => {
    if (!agent) {
      throw new Error("Agent is not found")
    }

    const contacts = agent.getContacts(connect.ContactType.TASK)

    if (!contacts.length) {
      throw new Error("No incoming task found")
    }

    // TODO: Validate whether we need to find the task by contactId.
    // I don't think we can have multiple tasks at the same time
    const task = contacts[0]

    return task
  }


const endTask = (): Promise<string> => {
    const task = getCurrentTask()

    const connections = task.getConnections()
    if (!connections || !connections.length) {
      throw new Error("No connections found for the task")
    }

    const taskConnection = connections[0]

    return new Promise((resolve, reject) => {
      taskConnection.destroy({
        success: () => resolve("Success ending task"),
        failure: (err) => reject(err),
      })
    })
  }

<Button name="endTask" size="md" type="button" onClick={endTask} />

The error is thrown when running the getConnections() method.

@vtrofin
Copy link
Author

vtrofin commented Sep 25, 2023

I got it, i needed to install the amazon-connect-taskjs api.

@vtrofin vtrofin closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant