I am building a FB bot and am trying to find a way to segment my answers to certain user inputs.
As of right now I have a large switch-case of over 600 entries but was wondering if it would be possible to segment it into several smaller lists in which I could run a single Promise to run through all async.
Here's what I have considered and already attempted:
- 1 switch-case: works, but seems awkward as the cases vary vastly by subject. i.e conversational cases ("hi, hey! etc) and certain requests for restaurants or events.
- Hashtable lookup - same problem as above - seems clunky and awkward to mix different subjects.
- Custom Promise that ignores rejects() and stops at first resolve. This worked for my segmented lists that were all Promisified but in regards to the reject case I was unable to get a response... I tried: - var t1 = test.switchCase1(event); //switch case 1 - restaurants var t2 = test.switchCase2(event); //switch case 2 - conversation var t3 = test.switchCase3(event); //switch case 3 - misc //resolve first, ignore rejects if (!Promise.first) { Promise.first = function (promise) { return new Promise ( (resolve,reject) => { promise.forEach( (prs) => { Promise.resolve(prs) .then(resolve); }) }) } } Promise.first([t1,t2,t3]).then(response => { utils.callSendAPI(response); //sends response to user });
Am I looking at this the wrong way? I've looked up tons of options such Object literal lookup but nothing seems to provide an answer to what I'm looking for.
