Dial pad implementation for reply extensions in Twilio SDK - node.js

I'm implementing call based application using twilio SDK and Ract + Node.js. I have the following requirement.
During an incoming or outgoing (audio) call, a user(any user that’s using the system to call) should be able to see the number pad button.A user should be able to open a popup with the number pad and be able to press numbers. When a user uses the dial pad to press numbers the pressed numbers should be communicated to the other end.
I tried searching the documentation for related methods. found that we can use SendDigits function and implemented some basic logic to trigger when click on a custom button on call screen. but it seems it is not sending the data to other end.
const sendDigit = () => {
console.log("Press 1");
outboundCall.sendDigit('1');
};
if anyone can guide me on how to do this would be a great help. basically, I want to have a dial pad on incoming and outgoing calls and then send press buttons according to the request by other end.

Your code has a function call to sendDigit but the function is called sendDigits.
const sendDigit = () => {
console.log("Press 1");
outboundCall.sendDigits('1');
};

Related

Blind Call Transfer in Asterisk | ari-client (Node.js)

Precise overview about the flow:
I am calling my initial extension(100) using Zoiper through Twilio sip domain using Zoiper as soft phone which actually direct the call to my asterisk server.
Now when my call is in asterisk server I'm trying to forward it to another extension using Zoiper. I have already configured it according to documentation provided by asterisk will also be attaching the reference links.
I just want to forward the current call to a particular extension. So please can anyone guide me that how it can be possibly done?
ari-client
bridge.once(‘BridgeAttendedTransfer’, event => {
var transferee = new ari.Channel(event.transferee.id);
transferee.continueInDialplan({
context: event.context,
extension: event.exten,
priority: 1
});
});
extension.conf
exten => 201,1,Dial(SIP/201,20,tT)
features.conf
blindxfer = #2 ("#2" or "##" instead of "#1")
atxfer = *2
transferdigittimeout = 1; Number of seconds to wait between digits when transferring a call
xfersound = beep ; to indicate an attended transfer is complete
xferfailsound = beeperr ; to indicate a failed transfer
transferdialattempts = 3 ; Number of times that a transferer may attempt to dial an extension before
being kicked back to the original call.
transferretrysound = "beep" ; Sound to play when a transferer fails to dial a valid extension.
transferinvalidsound = "beeperr" ; Sound to play when a transferer fails to dial a valid extension
Using Zoiper to make a transfer
References:
https://wiki.asterisk.org/wiki/display/AST/Feature+Code+Call+Transfers
https://www.aska-ltd.jp/en/blog/185
https://community.asterisk.org/t/call-transfer-not-working-on-softphones/33817
https://asteriskfaqs.org/2020/12/22/uncategorized/handling-transfers-with-ari.html
Trying to implement blind call transfer.

Update a bot message after responding to a slack dialog

I'm having some issues to update an interactive message after responding to a slack dialog. I'm using botkit on a node.js server.
Here is my workflow:
User trigger an interactive message via a slash command
User click a button on that message
A dialog pops up, user fill the form and validate
Something is done on the server side
The first message should update
Now, here is the logic I'm using:
User trigger an interactive message via a slash command
Nothing fancy, I use:
controller.on('slash_command', function (bot, message)
Then I parse the command, and send the appropriate message, with the appropriate attachments (buttons)
User click a button on that message
Same, I use the event sent by botkit:
controller.on('interactive_message_callback', function (bot, message)
Then I create a dialog:
var dialog = bot.createDialog(
'Which book?',
JSON.stringify(callback),
'Ok'
)
Here I'm doing something really (really) dirty, and should not be done. But that's the only way I found to update the initial message after the dialog is filled.
The callback_id actually contains an object, with the response_urlof the initial message (and something to identify the form).
A dialog pops up, user fill the form and validate
Something is done on the server side
Here, I use once more the event provided by botkit:
controller.on('dialog_submission', function (bot, message)
then I parse the message.submission.callback_id and detect the response_url. With this, I can create an object I call originalMessage.
The first message should update
At the moment I use :
bot.replyInteractive(originalMessage, 'DONE, everything is saved.');
with originalMessagecontaining the response_url of the first message.
It does work. The first message is being replaced by the new one.
But I'm really not happy with that solution, and was wondering if I was missing something somewhere. I've seen couple apps having that type of workflow, so there must be a way.
Thank you for your help :)
I wrote to Slack to ask about this situation and got a great suggestion from Mark P:
Use the state dialog field to pass the original response_url to the dialog. Then when you receive the dialog data, you can use state instead of response_url.
I just tried it and it worked great. No need to store any state on your own server.
I don't know how that would work exactly with Node and botkit, since that's not what I use.
To flesh this out a bit more:
Someone clicks a button and Slack POSTs about that interaction to your configured "Request URL".
From Slack's payload, get the "response_url" value.
When you call dialog.open in the Slack API, pass along this response_url as the "state" value.
When the dialog is submitted, Slack again POSTs to your "Request URL".
From Slack's payload, get the "state" value and use it as a response_url.
Profit!
This only works if you hold the original message object somewhere on your server for future reference.
So on creating the interactive dialog store it somewhere and add a reference. I use uuids.
let newId = uuid();
messageStore[newId] = message;
var dialog = bot.createDialog(
'My Dialog',
'idPrefix_' + newId,
'Submit'
).addText('Sample Input', 'input', '');
bot.replyWithDialog(message, dialog.asObject());
Then once you get your interactive dialog response back disassemble the prefix and the uuid and get your original message object back from the servers memory. Then use ´replayInteractive` there.
controller.on('dialog_submission', function handler(bot, message) {
if (message.callback_id.indexOf('idPrefix') === 0) {
let id = message.callback_id.substr('idPrefix_'.length);
bot.dialogOk();
let originalMessage = messageStore[id];
bot.replyInteractive(originalMessage, {
text: 'replacing the original message with this.'
});
}
});
Be careful that you do not create a memory leak here. You have to find a way to clean up your messageStore over time.

Using the Bot Framework to send message on the user's behalf

I'm currently attempting to accept voice input from the user, feed it into the Bing Speech API to get text, and pass that text as a user response. I've gotten as far as receiving the text back from Bing, but I'm not sure how to send that text as a user response. I've been scouring GitHub, so any feedback is appreciated. Relevant code is below:
function(session){
var bing = new client.BingSpeechClient('mykey');
var results = '';
var wave = fs.readFileSync('./new.wav');
const text = bing.recognize(wave).then(result => {
console.log('Speech To Text completed');
console.log(result.header.lexical)
console.log('\n');
results.response = result.header.lexical;
});
}]
You should use session.send.
I recommend you to take a look to the intelligence-SpeechToText sample, where a similar scenario is being shown.
Update: Figured it out (sorta). In order to take advantage of sending this user input back, I had to use another card. Within the context of the card, I'm able to use the imBack function

how to connect extension with content script in Firefox for android? [duplicate]

I just noticed that the tabs API is only available for the desktop not for Android. In the past I have used this code to send messages to my content scripts:
sendMsgToTabs(msg) {
return browser.tabs.query({}).then(tabs => {
let msgPromises = []
for (let tab of tabs) {
let msgPromise = browser.tabs.sendMessage(tab.id, msg)
msgPromises.push(msgPromise)
}
return Promise.all(msgPromises)
})
}
But how am I supposed to do that when the tabs API is not available?
I mean the only thing I can think of is to constantly send empty messages from the content scripts to the background script and whenever the background script has new information then it can send a direct response to one of these messages. But that sounds horribly inefficient. There must be a better way, right?
As of Firefox 54, use .tabs.sendMessage()
As of Firefox 54, the tabs API is supported on Firefox for Android.
Alternative for versions of Firefox prior to Firefox 54.
The storage API is stated as supported in Firefox for Android. Thus, while I have not tested it, a method you could use to send data to content script would be to save a value using chrome.storage.local.set(). By listening to the chrome.storage.onChanged event in your content script(s), you can then be notified of that data being stored/changed. This will provide an event driven way to send a message (i.e. stored data) to the content script.
In order to differentiate between receiving the data in different tabs, you will need to establish a protocol for what the data you save means. This could be as simple as just a particular saved key/value meaning that all content scripts should send a message to the background script to get more information, or more complex where you send/store something like:
{
contentScriptMessage: {
tab: 14,
frame: 1234,
message: 'Some data'
}
}
In each content script's chrome.storage.onChanged listener, it can then ignore any changes that are not to the tab/frame in which it is running.
This methodology will require fleshing out as you try to implement it. Hopefully, at least part of the chrome.tabs API will be implemented for Android in the near future.

How can I simulate latency in Socket.io?

Currently, I'm testing my Node.js, Socket.io server on localhost and on devices connected to my router.
For testing purposes, I would like to simulate a delay in sending messages, so I know what it'll be like for users around the world.
Is there any effective way of doing this?
If it's the messages you send from the server that you want to delay, you can override the .emit() method on each new connection with one that adds a short delay. Here's one way of doing that on the server:
io.on('connection', function(socket) {
console.log("socket connected: ", socket.id);
// override the .emit() method
const emitFn = socket.emit
socket.emit = (...args) => setTimeout(() => {
emitFn.apply(socket, args)
}, 1000)
// rest of your connection handler here
});
Note, there is one caveat with this. If you pass an object or an array as the data for socket.emit(), you will see that this code does not make a copy of that data so the data will not be actually used until the data is sent (1 second from now). So, if the code doing the sending actually modifies that data before it is sent one second from now, that would likely create a problem. This could be fixed by making a copy of the incoming data, but I did not add that complexity here as it would not always be needed since it depends upon how the caller's code works.
An old but still popular question. :)
You can use either "iptables" or "tc" to simulate delays/dropped-packets. See the man page for "iptables" and look for 'statistic'. I suggest you make sure to specify the port or your ssh session will get affected.
Here are some good examples for "tc":
http://www.linuxfoundation.org/collaborate/workgroups/networking/netem

Resources