I have tried a dozen ways to make a button on a webpage that's got a connected Twilio client voice call perform .sendDigits. This is the most recent try.
const dtmf_1 = document.getElementById('DTMF1');
dtmf_1.onclick = function(){call.sendDigits('1')};
This returns
Uncaught ReferenceError: call is not defined at dtmf_1.onclick (quickstart.js:46:79)
Frankly, I have no idea if fixing the reference is even going to work.
Does anyone have an example of working code that will play a DTMF tone on a live call with the Twilio JavaScript SDK?
Thanks to a timely comment by Tristan Blackwell (see above), I was able to fix this issue which was indeed a scoping problem.
The fix was to put the line
dtmf_1.onclick = function(){call.sendDigits('1')};
right under the line where the call is connected.
const call = await device.connect({ params });
Like so
const call = await device.connect({ params });
dtmf_1.onclick = function(){call.sendDigits('1')};
Related
I use Spreadsheet API to update sheets.
At some quite rare, and random, times the SpreadsheetsService.Query returns a (404) Not Found.
It is not just because there is not internet, or the service is down, because when it happens it keep happening for this specific query but not others.
It is quite weird :) Let me know if anyone has any hints.
The code is posted here below.
var requestFactory = new GDataRequestFactory("Some Name");
requestFactory.CustomHeaders.Add(string.Format("Authorization: Bearer {0}", credential.Token.AccessToken));
SpreadsheetsService service = new SpreadsheetsService("{my name}");
service.RequestFactory = requestFactory;
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = service.Query(query); //here comes the exception.
SpreadsheetEntry spreadsheet = null;
gdata is the older version of Sheets API and it's shut down. See Google's announcement here https://cloud.google.com/blog/products/g-suite/migrate-your-apps-use-latest-sheets-api
Whats happened what that I had actually upgraded everything to V4, but then it is normal very rarely to get 404s, and off course you need to retry after a timeout.
In my case I was still using the old API in the retries and so the 404 never got saved.
The output order is incorrect and at times test_1 and test_2 are undefined at the time of calling console.log
const fsp = require('fs').promises
const wss = newWebSocket(some_url)
// payload sent to websocket successfully using wss.send()
// message recieved from server
wss.on('message',async function (msg){
console.log(msg)
var test_1 = await fsp.readFile (file,'utf-8')
console.log(test_1)
var test_2 = await func_1 (test_1, args)
console.log(test_2)
});
Most likely this is because the time taken for processing the messages is longer than the time taken for transmitting new messages by the server. If it helps, I am accessing Bitfinex websocket API. Based on what I have read, it seems that storing incoming messages in a queue may help. However I am clueless about how to implement this. I would appreciate it someone could explain the solution in a simple and detailed manner - I am new to working with Javascript and still trying to wrap my head around its asynchronous nature.
I have looked at several answers to similar questions but feel that they are too complicated for a novice like me.
Any help would be appreciated. I am completely clueless here
I'm currently getting into developing alexa-skills. This is in fact the 1st time I'm trying this and I kinda works out good so far. However, I stumbled upon a problem which seems to be wide-spreaded but I couldn't find an answer how to solve it.
First things first:
I started this skill by following a tutorial. It might be that this tutorial is outdated and therefore this error appears.
I created a skill from the scratch and it works to the part where the LaunchRequest is invoked:
As you can see, I get my response as expected. (works on the test-environment as well as on alexa itself). Now, when try to call an IntentRequest, I just get the error-message:
The remote endpoint could not be called, or the response it returned was invalid.
As I can tell from the picture / request, the correct intent-request is called (in my case getSubscriberCount ) - And this is the point where I have no idea anymore on how to resolve this problem.
To keep things short, this here is the JS-part for the Intent:
case "IntentRequest":
// Intent Request
console.log(INTENT REQUEST)
switch(event.request.intent.name) {
case "GetSubscriberCount":
var endpoint = "my url"
var body = ""
https.get(endpoint, (response) => {
response.on('data', (chunk) => { body += chunk })
response.on('end', () => {
var data = JSON.parse(body)
var subscriberCount = data.items[0].statistics.subscriberCount
context.succeed(
generateResponse(
buildSpeechletResponse(`Du hast momentan ${subscriberCount} Abonnenten`, true),
{}
)
)
And this is causing my problems. To test what exactly is wrong, I tried the following:
Called the endpoint in my browser --> Correct output
Adjusted the "response" to the minimum to see if that works --> didn't work
Checked several sources related to this error --> didn't help either
I saw some approaches to get rid of this, since this seems to be a common issue, but I got lost. Someone mentioned an environment variable, which I couldn't put my hands on. Another one suggested to run the JSON request manually, which I tried, but leading to the same error.
Hopefully you can help me out here.
Assuming you AWS lambda, it might be because you didn't create your response right or your AWS lambda function had a error.
I'm making a discord bot, and I'm trying to make use of the createChannel function shown here in the documentation. For some reason, I am getting the following error:
TypeError: bot.createChannel is not a function.
My code is within a function which I pass a message to, and I have been able to create roles and add users to roles within the same function. It's just the createChannel function that's not working. Below is the relevant portions of the code.
const bot = new Discord.Client();
function makeChannel(message){
var server = message.guild;
var name = message.author.username;
server.createRole(data);
var newrole = server.roles.find("name", name);
message.author.addrole(newrole);
/* The above 3 lines all work perfectly */
bot.createChannel(server,name);
}
I have also tried bot.addChannel, and bot.ChannelCreate, since ChannelCreate.js is the name of the file which contains the code for this command. Also, I have attempted specifying channel type and assigning a callback function as well, but the main issue is the TypeError saying that this isn't a function at all. Any idea what I'm doing wrong?
Additionally, I plan to use ServerChannel.update() at some point in the future, so any advice on getting that to work once the previous problem is resolved would be greatly appreciated.
Alright, after a few days of trying things and going through the docs, I have discovered the solution. I am using a more recent version of Discord than the docs I was reading were written for. In the newer version, channels are created with a method in the server, not a client method. so, the code should be:
const bot = new Discord.Client();
function makeChannel(message){
var server = message.guild;
var name = message.author.username;
server.createChannel(name, "text");
}
The "text" value is the type of channel you are making. Can be text or voice.
I'll post a link to the most recent documentation for anyone else who encounters this problem here.
The answer should update documentation link to the GuildChannelManager which is now responsible for creating new channel.
(Example from docs)
// Create a new text channel
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
.then(console.log)
.catch(console.error);
https://discord.js.org/#/docs/main/stable/class/GuildChannelManager
#Jim Knee's I think your answer is v11, I'm new in discord.js, using Visual Studio Code's auto-code thingy. You can do all the same things except your thing must be this. If you are poor people, getting errors on doing #Jim Knee's answer, this is the place for "YOU!"
Get rid of server.createChannel(name, "text/voice");
And get it to THIS server.channels.create(name, "text/voice");
Hope I can help at least ;)
I'm just a new guy here too
I think you have not logged in with your bot.
From the docs:
const Discord = require('discord.js');
var client = new Discord.Client();
client.login('mybot#example.com', 'password', output); // you seem to be missing this
function output(error, token) {
if (error) {
console.log(`There was an error logging in: ${error}`);
return;
} else
console.log(`Logged in. Token: ${token}`);
}
Alternatively, you can also login with a token instead. See the docs for the example.
I've been following along with this
https://github.com/songz/OpenTokNodeJS
I posted an issue but thought I would try here as well.
I've been working at this for a minute and can't seem to get it running.
Here's my error
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
I'm guessing it has something to do with my api key, and to be honest i'm not 100% where i'm supposed to even put it. I've tried a few methods. First I replaced the lines in app.js
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;
with
var OTKEY = (my api key);
var OTSECRET = (my secret);
but when i run $ node app.js, nothing happens, and I get the error
I've also tried adding the key and secret to the package.json file like so
{
"name":"NodeOpenTok",
"version":"0.0.2",
"dependencies":{
"opentok":"44456952",
"express":"7f2ecae114cd4095a1ed689ff63910f1ea79444b",
"ejs":""
}
}
but I get the same errors. any ideas?
thanks for making this, looks great, can't wait to get it working!
my name is Song and I believe I can help you. When I wrote the following code, I am simply setting the variables OTKEY and OT_SECRET.
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;
You can similarly replace the key and secret directly:
var OTKEY = "1234";
var OTSECRET = "1abbababaabcabc";
process.env.TB_KEY and process.env.TB_SECRET pulls out the variables from my system environment . I do it this way because of security reasons ( I don't want to accidentally push my key/secret to github ). To set variables for your system environment, open your bash profile and add the following lines:
export TB_KEY='1234'
export TB_SECRET='1abbababaabcabc'
Again, setting the environment variables is not necessary to get your code to work. The simplest way to go is to simply set the variables OTKEY and OTSECRET.
Good Luck!