Skip to main content

API

Set End User Token

const connection = new RTASUI()
.setToken("eyJhbGciOiJIUzI1N3Cy...")

Set SignalR Url

const connection = new RTASUI()
.setUrl("https://rtas.example.url")

Set LogLevel

See all options available: here

  • By default is None = 6
  • For debugging, we recommend using Debug = 1
const connection = new RTASUI()
.setLogLevel(1)

Set Element

Set HTML element where should be render UI

  • You can use id like: #rtas
  • You can use classess like: .some_class
  • You can use complex selectors like: div.some_class > main
const connection = new RTASUI()
.setTargetElement("#rtas")

Languages

Languages supported: "PT_PT" , "EN_US"

// Set language
// If is not defined, the agent language will be used if is supported. if not it will use fallbackLanguage
const connection = new RTASUI()
.setLanguage("PT_PT")
// Set fallback language
// If is not defined, it will be used EN_US
const connection = new RTASUI()
.setFallbackLanguage("EN_US")

Connection Callbacks

On Connection Established

const connection = new RTASUI()
.setOnConnectionEstablishedCallback(
() => console.log("Connection Established")
)

On Connection Close

const connection = new RTASUI()
.setOnConnectionCloseCallback(
(error) => console.log("Connection Close")
)

On Error

const connection = new RTASUI()
.setOnErrorCallback(
(errorData) => console.log("OnError -> ", errorData)
)

Types

warning

The section Transaction Callbacks and Registration Callbacks , only are available after applying the type

Set Transaction Type

const connection = new RTASUI()
(...)
.setTransactionType()

Set Registration Type

const connection = new RTASUI()
(...)
.setRegistrationType()

Transaction Callbacks

On Transaction Pending

const connection = new RTASUI()
.setTransactionType()
.setOnTransactionPendingCallback((data) => {
console.log("OnTransactionPending => ", data);
// data: {
// "application_name": "Your Application",
// "contract_key": "jGa/YXvUIi38xwwZUNETGyoesAmSjlCa2g9K/h/NQR8=",
// "deeplink_url": "https://open.dev.trustfactor.securityside.com/transaction?contractKey=...",
// "transaction_expiration": 1678108194,
// "transaction_id": "9bd7c8e246a64d0bac2ca7e32ef10f83",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

On Transaction Accepted

const connection = new RTASUI()
.setTransactionType()
.setOnTransactionAcceptedCallback((data) => {
console.log("OnTransactionAccepted => ", data);
// data: {
// "application_name": "Your Application",
// "contract_key": "jGa/YXvUIi38xwwZUNETGyoesAmSjlCa2g9K/h/NQR8=",
// "device_key": "vUdD4bmV2+BKSDidO7CN44R2085nnDbz1oMcaCw3Cuw=",
// "transaction_id": "9bd7c8e246a64d0bac2ca7e32ef10f83",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

On Transaction Declined

const connection = new RTASUI()
.setTransactionType()
.setOnTransactionDeclinedCallback((data) => {
console.log("OnTransactionDeclined => ", data);
// data: {
// "application_name": "Your Application",
// "contract_key": "jGa/YXvUIi38xwwZUNETGyoesAmSjlCa2g9K/h/NQR8=",
// "device_key": "vUdD4bmV2+BKSDidO7CN44R2085nnDbz1oMcaCw3Cuw=",
// "transaction_id": "9bd7c8e246a64d0bac2ca7e32ef10f83",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

On Transaction Expired

const connection = new RTASUI()
.setTransactionType()
.setOnTransactionExpiredCallback((data) => {
console.log("OnTransactionExpired => ", data);
// data: {
// "application_name": "Your Application",
// "contract_key": "jGa/YXvUIi38xwwZUNETGyoesAmSjlCa2g9K/h/NQR8=",
// "transaction_id": "9bd7c8e246a64d0bac2ca7e32ef10f83",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

Registrations Callbacks

On Registration Pending

const connection = new RTASUI()
.setRegistrationType()
.setOnRegistrationPendingCallback((data) => {
console.log("OnRegistrationPending -> ", data);
// data: {
// "application_name": "Your application",
// "deeplink_url": "https://open.dev.trustfactor.securityside.com/register?payload=djIAAAAAAABkB...",
// "qr_code": "iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0CAIAAABEtEjdAAAfr0lEQVR4nOzdT6gkV/k38Lm372RmMiZxM...",
// "qr_code_expiration": 1678104748,
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

On Registration Success

const connection = new RTASUI()
.setRegistrationType()
.setOnRegistrationSuccessCallback((data) => {
console.log("OnRegistrationSuccess -> ", data);
// data: {
// "application_name": "Your Application",
// "contract_key": "7D/Iw9i3NdYLbHfw0UsVk3LcJo8PpQXoOPIRBhvF4Bk=",
// "device_info": {
// "device_model": "TFVA",
// "manufacturer": "SecuritySide",
// "marketing_name": "SecuritySide TFVA",
// "name": "Virtual Agent #1",
// "operating_system": "TFVA",
// "os_version": "1.0"
// },
// "device_key": "N+RlRWij82dHZ4TJ/slTbRP+UltX9SGC5DMhZOULbP4=",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

On Registration Expired

const connection = new RTASUI()
.setRegistrationType()
.setOnRegistrationExpiredCallback((data) => {
console.log("OnRegistrationExpired -> ", data);
// data: {
// "application_name": "Your Application",
// "user_display_name": "John Doe",
// "user_id": "john.doe"
// }
})

Build

This method should be the last method to be executed. This will start the connection with websocket and start to rendering the UI.

warning

If misconfigured, this method will throw an error. To prevent the application from breaking, we recommend that you place a 'try catch' around the code

const connection = new RTASUI()
.setTargetElement("#rtas")
.setToken("eyJhbGciOiJIUzI1N3Cy...")
.setUrl("https://rtas.example.url")
.setOnErrorCallback((errorData) => console.log("OnError -> ", errorData))
.setOnConnectionEstablishedCallback(() => console.log("OnConnectionEstablished -> "))
.setRegistrationType()
.setOnRegistrationPendingCallback((data) => console.log("OnRegistrationPending -> ", data))
.setOnRegistrationExpiredCallback((data) => console.log("OnRegistrationExpired -> ", data))
.setOnRegistrationSuccessCallback((data) => console.log("OnRegistrationSuccess -> ", data))
.build();

Close Connection

This method is used when after connecting, you want to close (for example, because you have navigated to another page)

when you get a final state like, for example: "Accepted" or "Rejected", you won't need to run this method, it will automatically terminate the connection, but if it runs it won't cause any problems either.

connection.closeConnection()

Retry Connection

This method is used after losing the connection e you want to re-establish the connection (for example, clicking into a button)

connection.retry()