【发布时间】:2021-08-28 04:35:50
【问题描述】:
我正在尝试使用 twilio 作为一种在将数据添加到我的 firebase 帐户(“child_added”)时收到警报的方式。我正在使用 node.js 并已安装并按照所有说明在我的计算机上获取 twilio。然而,每次我运行我的应用程序时,我都会收到以下错误:
require.js:1958 GET file:///Users/KV/CS/ErrandBoi2/twilio.js net::ERR_FILE_NOT_FOUNDreq.load @ require.js:1958load @ require.js:1682load @ require.js:832fetch @ require.js:822check @ require.js:854enable @ require.js:1173enable @ require.js:1554(anonymous function) @ require.js:1158(anonymous function) @ require.js:134each @ require.js:59enable @ require.js:1110init @ require.js:786(anonymous function) @ require.js:1457
require.js:168 Uncaught Error: Script error for "twilio"
http://requirejs.org/docs/errors.html#scripterror
换句话说,我的计算机找不到 twilio.js 文件,我认为它应该在我的 node_modules 中。我附上了我的代码,如果我做错了什么,请告诉我。由于我已经添加了有关 twilio 的行,因此一旦按下提交按钮,我的表单操作就无法正常工作。
我到处寻找“twilio.js”文件,但节点说明告诉我只需通过 npm 下载模块。我基本上想将解决方案移到我的公共网站上,看看它是否可以工作......
// Creates a variable called databaseLink that links to our database.
var databaseLink = new Firebase('https://errandboi-f1cf5.firebaseio.com/');
// Create javascript variables that link our previous HTML IDs. Remember, we can't use regular HTML inside a script tag, so we need to use JQuery to reference any previous HTML. A $ means we are using JQuery
var messageField = document.getElementById('task');
var nameField = document.getElementById('name');
var contactField = document.getElementById('contact');
var locationField = document.getElementById('location');
var miscField = document.getElementById('misc');
var messageList = $('#example-messages'); // DELETE MAYBE?????
// Twilio Credentials
var accountSid = '[MY_ACCOUNT_SID]';
var authToken = '[MY_AUTH_TOKEN]';
//require the Twilio module and create a REST client
function push() {
databaseLink.push({
name:document.getElementById('name').value,
task:document.getElementById('task').value,
contact:document.getElementById('contact').value,
location:document.getElementById('location').value,
misc:document.getElementById('misc').value,
})
require(['twilio'],function(twilio){
var client = twilio(accountSid, authToken);
ref.on("child_added", function(snapshot, prevChildKey) {
var newPost = snapshot.val();
client.sms.messages.create({ // if "messages.create" doesnt work, try "sendMessage" or "sms.messages.create"
to:'+13177302557',
from:'+13173644864',
body:'You got a new request: \n' + newPost.name + '\n' + newPost.task + '\n' + newPost.contact + '\n' + newPost.location + '\n' + newPost.misc,
}, function(err, message) {
console.log(message.sid);
});
});
});
};
<DOCTYPE! html>
<html>
<head>
<meta charset="UTF-8">
<!-- Twilio Library imporrted-->
<!-- <script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script> -->
<!--THIS IS NEEDED TO IMPORT FIREBASE LIBRARIES -->
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<!-- THIS IS JUST A NICE LOOKING FONT -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<!--THIS IS NEEDED TO IMPORT JQUERY LIBRARIES -->
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<!-- THIS IS TO IMPORT MY JS FILE -->
<script data-main="index" src="require.js"></script>
<!-- <script src="index.js"></script> -->
<link href="style.css" rel="stylesheet" />
<title>Btown Errands</title>
</head>
<body>
<div id="container">
<header>
<h1 class="title">Btown Errands</h1>
</header>
<div id="banner">
<h2>Your Helping Hand in Every Situation</h2>
</div>
<div id="content">
<p class="content">Ever have an emergency while you are in class? Life has got you all tied up but your tasks won't do themselves? Well, you are at the right place for help. Let ErrandBoi take the stress off your shoulders while you can do what really matters. Simply, fill out the form below with any* task that you may need help with and one of our drivers will help you out as soon as possible!</p>
<br><br><br><br><br><br><br><br><br>
<div class="form-style-5">
<form action="index.html">
<fieldset>
<legend><span class="number">1</span> Your Information</legend>
<input type="text" name="field1" id="name" placeholder="Your Name *">
<input type="email" name="field2" id="contact"placeholder="Contact Information (Email, Phone Number, etc.) *">
<input type="location" name="field3" id="location" placeholder="Your Location (i.e. McNutt, Hodge Hall, exact address, etc.)*">
<input type="text" name="field4" id="misc" placeholder="Miscellaneous Information That May Be Important"></textarea>
<label for="job">Urgency:</label>
<select id="job" name="field5">
<optgroup label="Urgency level: just for us to prioritize properly">
<option value="Not Urgent">Low (ETA: Up to an hour)</option>
<option value="reading">Normal (ETA: Up to 45 mins)</option>
<option value="boxing">Critical (ETA: ASAP!)</option>
</optgroup>
</select>
</fieldset>
<fieldset>
<legend><span class="number">2</span>Task that needs completion</legend>
<input type="text" id="task" name="field6" placeholder="Let Us Know How We Can Help!*"></input>
</fieldset>
<input name="submit" type="submit" value="Submit" onClick="push()"/>
</form>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
你在什么操作系统上运行这个?
-
我正在用谷歌浏览器试试这个
-
你为什么在没有网络服务器的情况下运行它?
标签: javascript jquery html node.js twilio