0

I am using ding-dong for AGI server, and i have a call flow created using bpmn-io that i want to run. So I have integrated bpmn-engine

I have created three nodes

// 1: Hello
// 2: Welcome
// 3: Bye

Here is the code I have written

var Server = require('ding-dong');
var parserEngine  = require('../bpmn_engine/parser');
const { EventEmitter } = require('events');

// global promise is created so that each event is played by AGI one by one
var promise ={};
// This is for bpmn engine
const listener = new EventEmitter();

// AGI server handler
var handler = function (context) {
  // Call starts when 'variables' received on context event
  // context contains all commands and stuf provided by ding-dong
  promise = context.onEvent('variables')
    .then(function (vars) {
      // delete require.cache[require.resolve('../bpmn_engine/parser')]
      parserEngine  = require('../bpmn_engine/parser')
      parserEngine.engine.execute({
       listener,
        variables: {
          // context is passed to bpmn so that we can stream files on any activity
          context: context
        }
      });
    });
};

// AGI server created
var Server = new Server(handler);


listener.on('activity.start', async (elementApi, engineApi) => {
  console.log("Element Name",elementApi.name);
  await elementApi.environment.variables.context.streamFile('/var/lib/sounds/file_name');
   
});

module.exports = Server;

In the above code I have created the bpmn-engine instance and passed the listener object, bpmn-engine will emit the event on that.

But in this case it logs all the element names like

Hello
Welcome
Bye

and call is running but it does not play anything, as far as i understand, just an assumption as listener is async in nature and is not related to agi call, so its prints all the names at that time agi call code block is exexuted (call is still running as we have not signled to end call) and it does not wait to play any voice file.

Now If i use the same promise that i got from call connected then it works

listener.on('activity.start', async (elementApi, engineApi) => {
      console.log("Element Name",elementApi.name);
      promise =  promise.then(function(result){
        return elementApi.environment.variables.context.streamFile('/var/lib/sounds/file_name');
      }); 
    });

it prints all the element names first then one by one it executes, that is kind misleading in logs.

Issue in this is that as we are using same promise, so if there are 2 calls at a time then it plays sequentially one message for first call and then first message for second call, or the way promises work.

I tried using new promise at all then it does not work, it just work with promise that got created from on variables event

any solution on this? or is there any otherway to integrate ding-dong and bpmn-engine

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
  • streamFile('/var/lib/sounds/file_name - is it exists? AGI is simple text protocol. Where is debug trace(wireshark/tcpdump)? – arheops May 26 '23 at 17:56
  • there is nothing on console regarding errors, yes these files exists on my asterisk server – Sunil Garg May 27 '23 at 09:53

0 Answers0