Hello to everyone who follows the adventures of Pavlov in telephony. A few days ago we added a new subsystem to Voximplant. As a developer involved in this pikachu, I want to share the inner kitchen of the development. We have added a platform to build messenger apps. Whether it is chats, corporate communication systems, messaging devices - all that is enough to transfer text information.
I hope that the technical information and all sorts of dry figures about the server part of the platform will be told to you by one of my colleagues a little later in our blog.
Connecting a WebSDK library with a helper
')
<script type="text/javascript" src="//cdn.voximplant.com/edge/voximplant.min.js"></script> <script type="text/javascript" src="//cdn.voximplant.com/edge/voximplant-websdk-helper.js"></script>
If you have been familiar with VoxImplant WebSDK before, it will be strange for you that there is an additional library: voximplant-websdk-helper. This is a small lib that I use in internal development and testing. It reduces event subscriptions for regular operations, such as login and initialization.
VoxImplantHelper.Login.LoginWithPass({ micRequired: false }, 'pavel_a@bar.foo.voximplant.com', 'foobar123456', {}, true).then((e) => { log('Connection successful'); }).catch((e) => { log('ERR:' + e, true); });
Now it is easy and natural to get an instance of the messenger:
let msgInst; VoxImplantHelper.Login.LoginWithPass({ micRequired: false }, 'pavel_a@bar.foo.voximplant.com', 'foobar123456', {}, true).then((e) => { console.info('Connection successful'); msgInst = VoxImplant.getMessenger(); initMessenger(); }).catch((e) => { console.info('ERR:' + e, true); }); function initMessenger(){
This is a little easier and faster than through standard events. But if you want to add messaging to an already ready application, then simply add this code to any convenient place after login:
msgInst = VoxImplant.getMessenger(); initMessenger(); function initMessenger(){
First, let's subscribe to the Event of creating a new dialogue in order to receive an instance of the created dialogue when it is ready:
let conversations = []; msgInst.on(VoxImplant.MessagingEvents.onCreateConversation,(e)=>{ conversations.push(e.conversation); })
Our API is based on Conversation. These are conversations between 1 or more users. We did not limit the creation of dialogs to at least 2 users, so you can do service and buffer dialogues between devices of the same user.
const participants = [{user_id:"pavel_b@bar.foo"}];
We made the message sending system minimalistic. There are no additional notifications that the system received, processes and processed your request for the message. Everything happens too fast to send such a bunch of messages.
You simply send a message to the dialogue, and all participants in the dialogue, including you, receive a new message.
Sending a message is done in 1 line, without additional preparation. A step earlier, we saved the new dialogue into an array of conversations. We will receive it and send a message.
let currentConv = conversations[0]; currentConv.sendMessage(", !");
Do not forget to add new messages. Well, you can then display the results somewhere
msgInst.on(VoxImplant.MessagingEvents.onSendMessage,(e)=>{ console.log(e.message.conversation);
This is the first article in a cycle of tutorials on developing web applications for our platform. Pavel and I will try to make the articles come out weekly on Wednesdays.