0

With Version 11.1 of Avayas IP Office, there is the new MTCTI-3 API available. It works by exchanging Protobuf objects over a websocket connection.

There is not much docummentation an virtually no sample code about this api and I have problems communicating with this api.

To observe objects, like users, you have to send subscriptions to the API. First step is to send a SubscribeLines, one should receive an answer which should proivde further information about users. With this information it should be possible to subscribe to these users.

I'm using java.net.http.WebSocket for my websocket client. Cennecting to IPO's websocket works afaik. But I'm not getting any responses or events from the IPO.

I would expect that the answer to SunbscribeLines is processed by WSListener.onBinary but I never receive a response.

Question: Has anyone here used this API and/or has any idea why why I do not get any answer from the api? Is there any working code (javascript, python or what ever will also be ok ;-)) using this api out there?

  • onOpen and on onPing show that the connection is established.

Code

Connection WS

HttpClient client = HttpClient.newBuilder()
        .version(Version.HTTP_1_1)
        .sslContext(sc)
        .authenticator(new BasicAuthenticator(user, pass))
        .build();
        
WebSocket ws = client.newWebSocketBuilder()
        .subprotocols("openapi")
        .buildAsync(URI.create(current_url), new WSListener())
        .join();

SubscribeLines

SubscribeLines subscribeLines = SubscribeLines.newBuilder()
        .setFlags(7)
        .build();
Subscribe subscribe = Subscribe.newBuilder()
        .setSubscribeId(linesSubId)
        .setRequestid(requestId++)
        .setLabel("test")
        .setTimeout(3600)
        .setLines(subscribeLines)
        .build();
Message msg = Message.newBuilder()
        .setSubscribe(subscribe)
        .build();

ByteBuffer buffer = ByteBuffer.wrap(msg.toByteArray());
CompletableFuture<WebSocket> cfws = ws.sendBinary(buffer, true);

System.out.printf("done(%b) exept(%b) cancel(%b) %n", 
                cfws.isDone(), cfws.isCompletedExceptionally(), cfws.isCancelled());
// Output: done(true) exept(false) cancel(false)

WSListener

To handle data sent from the IPO side we need an implemtation of WebSocket.Listener

private static class WSListener implements WebSocket.Listener {
    @Override
    public void onOpen(WebSocket webSocket) {
        Listener.super.onOpen(webSocket);
        System.out.printf("%1$tH:%1$tM:%1$tS.%1$tL onOpen%n", System.currentTimeMillis());
    }
    
    @Override
    public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean last) {
        System.out.printf("%2$tH:%2$tM:%2$tS.%2$tL onText %1$s%n", data, System.currentTimeMillis());
        return Listener.super.onText(webSocket, data, last);
    }
    
    @Override
    public CompletionStage<?> onBinary(WebSocket webSocket, ByteBuffer data, boolean last) {
        System.out.printf("%1$tH:%1$tM:%1$tS.%1$tL onBinary %1$s :>", System.currentTimeMillis());
        while(data.hasRemaining()) {
            System.out.printf(" %x", data.get());
        }
        System.out.printf("<:%n");
        return Listener.super.onBinary(webSocket, data, last);
    }
    
    @Override
    public void onError(WebSocket webSocket, Throwable error) {
       // ...
    }
    
    @Override
    public CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message) {
       // ...
    }
    
    @Override
    public CompletionStage<?> onPong(WebSocket webSocket, ByteBuffer message) {
       // ...
    }
    
    @Override
    public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String reason) {
        System.out.printf("%3$tH:%3$tM:%3$tS.%3$tL onClose %1$d %2$s%n", statusCode, reason, System.currentTimeMillis());
        return Listener.super.onClose(webSocket, statusCode, reason);
    }
}
Hajo Thelen
  • 1,095
  • 1
  • 11
  • 16

1 Answers1

1

I recently made some test on Avaya MTCTI3 api, I have to say it is much better than TAPI.

According to Avaya MTCTI3 offical document:

《IP Office™ Platform Description of MTCTI-3 API Introduced in Release 11.1.0.0 Version 1.0》
Ref link: https://www.devconnectprogram.com/site/global/products_resources/ip_office/releases/11_1/index.gsp#download-14

Page 21, the websocket protocol is "framed protocol-buffers in either direction"

Packet Info
4 octets 0x1 = Framed protocol buffer
N octets Protocol buffer payload

so the original code here:

ByteBuffer buffer = ByteBuffer.wrap(msg.toByteArray());

should change to something like this (not tested):

ByteBuffer bufferContent = ByteBuffer.wrap(msg.toByteArray());
byte[] header = new byte[]{0,0,0,1};
ByteBuffer buffer = ByteBuffer.allocate(header.length+bufferContent.array().length).put(header).put(bufferContent.array());

And, I have writen a simple MTCTI3 console tool with golang, check here: https://github.com/F-Sidney/gomtcti3

Nickwar
  • 11
  • 2