I am working on a IVR solution for small businesses in my local area but I am having trouble wrapping my head around how Node will handle menus. I could make a seperate Node server for each of my customers but I would like to have a single server that pulls each customer's IVR setup from a Mongo database or file when their number is called. I have an idea on how to save the menu structure in JSON but I am lost when it comes to turning that JSON into responses to <gather> inputs. I was thinking I could use a JSON structure like this in the DB (or maybe as a .json file on Amazon S3):
{
"menu": {
"id": 1,
"name": "Main",
"script": "Thank you for calling Local Company. To speak to sales press 1, ...",
"options": [
{
"name": "",
"action": "",
"value": "",
"next": ""
},
{
"name": "Sales",
"action": "dial",
"value": 12345678901,
"next": ""
},
{
"name": "Support",
"action": "dial",
"value": 12345678902,
"next": ""
},
{
"name": "Directions",
"action": "say",
"value": "Our offices are located at...",
"next": 1
},
{
"name": "Mailbox",
"action": "mailbox",
"value": "main",
"next": 1
}
]
}
}
Twilio developer evangelist here.
If you can return the JSON based on the number a user is dialling, then you could do something like this:
const Twilio = require('twilio');
app.post('/voice', (req, res) => {
const dialledNumber = req.body.To;
getIVRObjectFromPhoneNumber(dialledNumber, (IVRObject) => {
const twiml = Twilio.twiml.VoiceResponse();
if (typeof req.body.Digits !== 'undefined') {
// A user has pressed a digit, do the next thing!
const action = IVRObject.menu.options[req.body.Digits]
twiml[action.action](action.value);
} else {
// No digits yet, return the <Gather>
const gather = twiml.gather({
numDigits: 1
});
gather.say(IVRObject.script);
}
res.send(twiml.toString());
});
});
This doesn't quite use all of your object, I'm not sure what the values for next mean, but hopefully it's a start. The getIVRObjectFromPhoneNumber method is my made up, asynchronous method that returns a JavaScript object parsed from your example JSON above.
Let me know if this helps at all.
Related
So I got this problem.
I am trying to fetch a local json file from my project. The json file is stored in the src folder.
This is my json file
[
{
"name": "Sunsssset Beach",
"email": "info#sunsetbeach.com",
"image": "https://images.unsplash.com/photo-1439130490301-25e322d88054?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1489&q=80",
"price": 85,
"maxGuests": 18,
"lat": 60.393388,
"lng": 5.22872,
"description": "Get ready for some amazing sunsets as you sip a cocktail and watch dolphins play in the harbour below.",
"selfCatering": true,
"createdAt": "2020-09-04T09:07:10.367Z",
"id": "5f5203bedc17b0a4b302f211"
},
{
"name": "The Hideaway",
"email": "info#hideaway.com",
"image": "https://images.unsplash.com/photo-1551906993-c8b38a6ab201?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=666&q=80",
"price": 70,
"maxGuests": 2,
"lat": 60.425168,
"lng": 5.358141,
"description": "This secluded wilderness cabin is the perfect spot for a restful and cosy getaway.",
"selfCatering": true,
"createdAt": "2020-09-04T09:07:10.370Z",
"id": "5f5203bedc17b0a4b302f213"
},
{
"name": "Rest Easy",
"email": "management#resteasy.com",
"image": "https://images.unsplash.com/photo-1512552288940-3a300922a275?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=751&q=80",
"price": 120,
"maxGuests": 14,
"lat": 60.396779,
"lng": 5.235602,
"description": "Need some time off from your busy life to relax and unwind? Choose Rest Easy for the complete relaxation experience you desire.",
"selfCatering": false,
"createdAt": "2020-09-04T09:07:10.370Z",
"id": "5f5203bedc17b0a4b302f212"
}
]
And here is my project file
function Establishment() {
const [establishment, setEstablishment] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch("jsonfile")
.then((response) => {
// check if response returns ok
if (response.ok) {
return response.json();
} else {
setErrorHandle(true);
}
})
.then((data) => {
setEstablishment(data);
})
.catch((err) => {
console.log(err);
setErrorHandle(true);
})
.finally(() => setLoading(false));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Now I want to be able to press a button do display all of these items, and by clicking on one item, it should display only that item in a different page. How do I do that?
Let me know if there is anything else you need to solve this problem :)
Firstly if the JSON data is in a local in your file system then you do not need fetch or axios
Why you did not use Axios or Fetch?
Axios or Fetch use to get or post data into the server. In our case, we read on the local folder file so that we use map().
Note: most important when using Axios and Fetch we need URL parameter compulsory
Now what you are to do is:
1. Firstly Import the file wherever you want to use:
import data from "../static/data/myData.json";
2. Now you want to map through that Json file:
<div>
{
data.map(myData, index)=>{
return <div key={myData.id}>
<h1>{myData.name}</h1>
<h3>{myData.email}</h3>
</div>
}
}
</div>
So that is how you want to handle this situation obviously structuring the content the way you desire not with h1's and h3's like I did
Below is my code and I want to extract data under "specs" part like description, status etc. however I'm getting undefined when I capture the data and print it in the console. I have tried
let web = JSON.parse(jsondata);
let TestSuite = web["suite1"]["description"]
and this is providing data in console however, when I use this,
let id = web["suite1"]["specs"]["id"]
its gives undefined. Please help!
{
"suite1": {
"id": "suite1",
"description": "Login",
"fullName": "Login",
"failedExpectations": [],
"status": "finished",
"specs": [
{
"id": "spec0",
"description": "Should able to login into the Distribution management Webpage",
"fullName": "Login Should able to login into the Distribution management Webpage",
"failedExpectations": [
{
"matcherName": "",
"message": "",
"stack": "",
"passed": false,
"expected": "",
"actual": ""
}
],
"passedExpectations": [],
"pendingReason": "",
"started": "2018-09-06T06:57:42.740Z",
"status": "failed",
"duration": "7 secs",
"stopped": "2018-09-06T06:57:49.255Z",
"browserLogs": []
}
]
} }
JSON.parse(JSON.stringify(json)).suite1.specs[0].id
specs contains an array of objects. First, you need to get the object from the array and then get a value of the object.
Try this:
let id = web["suite1"]["specs"][0]["id"]
OR
let id = web.suite1.specs[0].id
Hope this will work.
When you do ["suite1"]["specs"], you select array. You need an index, which is the 0-th one in this case.
You can check that by typing Object.prototype.toString.call( data["suite1"]["specs"]).
You can try with:
data["suite1"]["specs"][0]["id"]
Or use the object property notation
data["suite1"]["specs"][0].id
Is it possible to create a loop in aws step function and loop through json input array?
I have a function generateEmails that creates array with n number of objects:
{
"emails": [
{
"to": [
"willow1#aaa.co.uk"
]
},
{
"to": [
"willow2#aaa.co.uk"
]
}, {
"to": [
"willow3#aaa.co.uk"
]
}
]
}
and now I want to call next function sendEmail for each object in emails array with something like this:
{
"email": {
"to": [
"willow#aaa.co.uk"
]
}
}
step function code:
{
"Comment": "A state machine that prepares and sends confirmation email ",
"StartAt": "generateEmails",
"States": {
"generateEmails": {
"Type": "Task",
"Resource": "arn:aws:lambda::prepare-confirmation-email",
"Next": "sendEmail"
},
"sendEmail": {
"Type": "Task",
"Resource": "arn:aws:lambda::function:template-service",
"End" : true
}
}
}
Is that possible to achieve?
Thanks!
Yes, the Step Functions Map state makes this easy.
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html
Map allows you to run the same set of operations to each item in an array. If you set the MaxConcurrency field to something larger than 1, then it will do these in parallel. Or you can set to 1 and it will iterate through sequentially.
For the scenario you described, the number of items will probably mean that "Inline" Map will work just fine. But if that list is larger and you want to fan out to higher concurrency, the recently launched Distributed Map feature will let you do so.
https://aws.amazon.com/blogs/aws/step-functions-distributed-map-a-serverless-solution-for-large-scale-parallel-data-processing/
I'm battling with the WikiEditor extension of MediaWiki 1.27. When a user tries to use the fancy image upload button from the enhanced editor toolbar, I get the message "You must be logged in to upload files."
So far I've narrowed it down to the user rights returned from the API being incomplete. I've tested with the following two API calls:
The one WikiEditor uses: action=query&meta=userinfo&uiprop=rights
returns:
{
"batchcomplete": "",
"query": {
"userinfo": {
"id": 1006,
"name": "john_smith",
"rights": [
"read",
"createpage",
"createtalk",
"writeapi",
"editmyusercss",
"editmyuserjs",
"viewmywatchlist",
"editmywatchlist",
"viewmyprivateinfo",
"editmyprivateinfo",
"editmyoptions",
"autocreateaccount"
]
}
}
}
However, this API call: action=query&list=users&ususers=john_smith&usprop=rights returns:
{
"batchcomplete": "",
"query": {
"users": [
{
"userid": 1006,
"name": "john_smith",
"rights": [
"block",
"createaccount",
"delete",
"bigdelete",
"deletedhistory",
"deletedtext",
"undelete",
"editinterface",
"editusercss",
"edituserjs",
"editcontentmodel",
"import",
"importupload",
"move",
"move-subpages",
"move-rootuserpages",
"move-categorypages",
"patrol",
"autopatrol",
"protect",
"editprotected",
"rollback",
"upload",
"reupload",
"reupload-shared",
"unwatchedpages",
"autoconfirmed",
"editsemiprotected",
"ipblock-exempt",
"blockemail",
"markbotedits",
"apihighlimits",
"browsearchive",
"noratelimit",
"movefile",
"unblockself",
"suppressredirect",
"mergehistory",
"managechangetags",
"deleterevision",
"read",
"createpage",
"createtalk",
"writeapi",
"editmyusercss",
"editmyuserjs",
"viewmywatchlist",
"editmywatchlist",
"viewmyprivateinfo",
"editmyprivateinfo",
"editmyoptions",
"autocreateaccount",
"edit",
"minoredit",
"purge",
"sendemail",
"applychangetags",
"changetags"
]
}
]
}
}
I'm totally stumped and at a loss of why these two very similar API calls return a different set of rights. As a result, users are not able to upload images via the enhanced editor button.
Is there a way to fetch data from Oracle UCM's JSON option and use this in Full Calendar. I createed a service to return data from calendar data in UCM, and want to display the events using fullcalendar.
Here is an example feed that I get back:
"ResultSets": {
{
"SQLLMCal": {
"fields": [
{ "name": "SINGLE_ELEMENT" },
{ "name": "Start" },
{ "name": "SCHOOL_TYPE" },
{ "name": "SCHOOL_TYPE_ID" },
{ "name": "Title" },
{ "name": "ENTRY_SIDE_GROUP" }
],
"rows": [
[
"141",
"3/17/11 12:00 AM",
"Elementary",
"3",
"Big Burger",
"1"
]
]
}
}
}
Thanks, Ken
need to parse your own data using a custom events function:
http://arshaw.com/fullcalendar/docs/event_data/events_function/
Okay, great example of "problem exists between keyboard and chair"! I just had to stare at the documentation and the answer was right there.
In my code, I have the following:
events: function(callback) {
By definition, this MUST be
events: function(start, end, callback) {
Once I added the start and end parameters, everything worked perfectly.
Thank you Adam for pointing me the the right direction!
Ken