amazon-connect / amazon-connect-chatjs

Amazon Connect ChatJS - a browser-based contact center integration API for Chat on the Agent and Customer side.
https://docs.aws.amazon.com/connect/latest/adminguide/what-is-amazon-connect.html
Apache License 2.0
91 stars 53 forks source link

Some type definitions are missing from versions above 2.0 #221

Closed kit-field-wk closed 2 weeks ago

kit-field-wk commented 3 weeks ago

I have some software that depends on "amazon-connect-chatjs": "^1.5.1"

This is dependency is getting old and we intend to upgrade to use a later version such as 2.2.4

However when I try to upgrade I get build-time typescript errors, about 40 of them.

We see that the amazon-connect-chatjs project is written in js (not in ts) so the auto generated types do not include the ones we rely on. Could type definitions be provided again?

The following code typechecks correctly with 1.5.1 but not with 2.2.4 and , as far as I can see, 2.2.4 does not include these types or equivalent one for us to use.

import "amazon-connect-chatjs";
import "amazon-connect-streams";

async (contact: connect.Contact) => {
  const connection = contact.getAgentConnection() as connect.ChatConnection;

  const controller: connect.ChatSession = await connection.getMediaController();

  controller.onConnectionEstablished((event) => {
    console.log(
      `chat websocket connection established (contactId: ${event.chatDetails.contactId})`
    );
  });
};

const f = ({Content}: connect.ChatTranscriptItem) => {
  JSON.parse(Content || "");
};

function App() {
  const someMadeUpItem: connect.ChatTranscriptItem = {
    Id: "dd",
    AbsoluteTime: "",
    Type: "MESSAGE",
    Content: "here is some content",
  };
  console.log(f(someMadeUpItem));
  return <div>Hello</div>;
}

export default App;

The following amazon-connect-chatjs commit deleted the src/index.d.ts file. This 600 line file included the type definitions that we still use.

Commit: 747ce9f2b22960403abb9a87098d786654d6f9fd By: Spencer Lepine, 11 months ago (May 10th, 2023 7:52 PM) Message: typescript support: auto-generate index.d.ts file (#162)

mhiaror commented 2 weeks ago

Thanks for connecting, please refer to the release notes for 2.0 update https://github.com/amazon-connect/amazon-connect-chatjs/releases/tag/2.0.0 We are not generating index.d.ts file instead of manually managing the typescript definitions.

You can refer to the ChatSessionObject using below code:

import "amazon-connect-streams";
import "amazon-connect-chatjs";
import { ChatSession } from "amazon-connect-chatjs";
....

const controller = await connection.getMediaController() as ReturnType<typeof ChatSession.create>;

  controller.onConnectionEstablished((event) => {
    console.log(
      `chat websocket connection established (contactId: ${event.chatDetails.contactId})`
    );
  });