Twilio Autopilot, best method to check mobile number in external database - function

I would like to use Twilio autopilot to build a whatsapp Chatbot. I need to know if a user has already used our service before. This means that on initiation, i get the data from an external source, i can then use functions to further specify the chatbot logic.
I am wondering what are the best options in the twilio environment to get that external data loaded in event or memory? I see webhooks are only for diagnostics, and i dont know what are the async capabilities of functions. Could someone elaborate a bit about the pro's and cons of different methods?
Thanks

you can take a look at The Autopilot Request. These request parameters are provided to your application (via a webhook associated with a task), where you can add additional logic to see if this is a new user or returning user and return the appropriate Autopilot Actions, one of which is Remember.

An approach would be setting a webhook that will determine if the User has used the system before on to the Assistant's assistant_initiation more info
The webhook can then reply with a JSON Remember + Redirect
Example -
{
"actions": [
{
"remember": {
"isNewuser": "true"
}
},
{
"redirect": "task://newUserTask"
}
]
}
OR
{
"actions": [
{
"remember": {
"isNewuser": "false"
}
},
{
"redirect": "task://oldUserTask"
}
]
}
Also since "isNewuser": "true" will be on the assistant's memory you can use that info on any following task until the session (4 Hours) expires.

Related

REST API which needs multiple different resources?

I'm designing a REST api for running jobs on virtual machines in different domains (Active Directory domains, the virtual machines with the same name can exist in different domains).
/domains
/domains/{dname}
/domains/{dname}/vms
/domains/{dname}/vms/{cname}
And for jobs, which will be stored in a database
/jobs
/jobs/{id}
Now I need to add a new API for the following user stories.
As a user, I want to run a job (just job definition, not the stored job) on an existing VM.
As a user, I want to run a job (just job definition, not the stored job) on VM named x, which may or may not exist. The system should create the VM if x doesn't exist.
How should the api be designed?
Approach 1:
PUT /domains/{dname}
{ "state": "running_job", "vm": "vm_name", "job_definition": { .... } }
Approach 2:
PUT /domains/{dname}/vms/{vm_name}
{ "state": "running_job", "job_definition": { .... } }
Approach 3:
PUT /jobs
{ "state": "running", "domain": "name", "vm": "vm_name", "job_definition": { .... } }
Approach 4: create a new resource, saying scheduler,
PUT /scheduler
{ "domain": "name", "vm": "vm_name", "job_definition": { .... } }
(what if I need to update some attributes of scheduler in the future?)
In general, hwo to design the REST API url which needs multiple resources?
How should the api be designed?
How would you design this on the web?
There would be an HTML form, right? With a bunch of input controls to collect information from the operator about what job to use, and which VM to target, and so on. Operator would fill in the details, submit the form. The browser would then use the form to create the appropriate HTTP request to send to the server (the request-target being computed from the form meta data).
Since the server gets to decide what the request-target should be (benefits of using hypertext), it can choose any resource identifier it wants. In HTTP, a successful unsafe request happens to invalidate previously cached responses with the same request target, so one possible strategy is to consider which is the most important resource changed by successfully handling the request, and use that resource as the target.
In this specific case, we might have a resource that represents the job queue (ex /jobs), and what we are doing here is submitting a new entry in the queue, so we might expect
POST /jobs HTTP/1.1
....
If the server, in its handling of the request, also creating new resources for the specific job, then those would be indicated in the response
HTTP/1.1 201 Created
Location: /jobs/931a8a02-1a87-485a-ba5b-dd6ee716c0ef
....
Could you instead just use PUT?
PUT /jobs/931a8a02-1a87-485a-ba5b-dd6ee716c0ef HTTP/1.1
???
Yes, if (a) the client knows what spelling to use for the request-target and (b) is the client knows what the representation of the resource should look like.
Which unsafe HTTP method you use in the messages that trigger you business activities doesn't actually matter very much. You need to use the methods correctly (so that general purpose HTTP connectors don't get misled).
In particular, the important thing to remember about PUT is that the request body should be a complete representation of the resource - in other words, the request body for a PUT should match the response body of a GET. Think "save file"; we've made local edits to our copy of a resource, and we send back a copy of the entire document.

Unable to receive Forge webhooks, or unable to get them to fire

I'm setting up an automated system to convert and visualise 3D models through the Forge APIs. The actual conversion and visualisation is pretty straight forward, but keeping track of the process is not as simple.
Autodesk recommends using webhooks, but documentation of this is quite sparse.
My main problem is that I'm unable to debug the webhooks. I get no indication to weather a hook has been posted or not.
I've read all of the similar questions here on stack overflow, in the FAQ and in the documentation (among others: Why is webhook workflow not taken into consideration when creating modelderivative job?).
I'm processing a conversion for a model with 'modelId'. And want to listen to the events 'extraction.updated'.
I'm registering a hook with a POST like this:
{
"callbackUrl":"https://my-service.com/callbacks/modelId",
"scope":{
"workflow":"modelId"
}
}
My job is registered like this:
{
"input":{
"urn":"{theUrnForTheModel}"
},
"output":{
"formats":[
{
"type":"svf",
"views":[
"3d",
"2d"
]
}
]
},
"misc":{
"workflow":"modelId"
}
}
From what I can see the hooks never fire. I don't get any errors or indications that something fail on my server.
Am I required to post hookAttribute when creating the hook? This is documented as not mandatory. Am I required to have a fixes endpoint on my end, or is it ok to include the specific model id in the url?
A few points to check:
What's the response on POST hook? Should return 201
Which verb does your /callbacks/modelId accepts? Should accept POST
Have you tried extraction.finished event?

With Braintree how to not save duplicate cards when creating a transaction?

I know that when I create a payment method I can use failOnDuplicatePaymentMethod to block duplicate cards. But when I use the storeInVaultOnSuccess option with Braintree_Transaction::sale, what is the best way to not save the card if it is already saved?
Edit:
Let me clarify my situation to make sure. On my checkout page I am currently using this JavaScript:
braintree.setup(
myToken,
'custom',
{
id: 'my-form-id',
hostedFields: {
...
},
onPaymentMethodReceived: function(obj) {
...
},
onError: function(obj) {
...
}
}
);
The customer fills in their CC number, CVV and expiration date and clicks submit and then that onPaymentMethodReceived callback fires. In that JS callback I make an AJAX call to my back-end and pass the nonce. On the back-end I call Braintree_Transaction::sale in order to charge the customer.
I always need Braintree_Transaction::sale to successfully complete so that the sale goes through. And then in addition so this sale, I want the card to be saved if the customer has checked "save my card" and the card isn't already saved.
On this checkout page, the customer does have the option to select a saved card instead of inputting all their card info again, but they may type all the card info in again(for an already saved card) instead of selecting the saved card.
How would you do it given this setup? Does your below setup still apply? If so how exactly would I integrate the below with my above setup? Or do I need to rearrange my UI/UX for this(I think this is a pretty standard checkout flow)?
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
There isn't a way to prevent duplicate payment methods when making a Braintree_Transaction::sale API call. However, you can still achieve your goal with some settings on your client. Here are those steps:
On your server, create a client token and include the customer_ID and the failOnDuplicatePaymentMethod parameters:
```
$clientToken = $gateway->clientToken()->generate([
"customerId" => "aCustomerId",
"options" => [
"failOnDuplicatePaymentMethod" => true
] ]);
```
Use this client token as your authorization when creating the Braintree client instance:
```
var createClient = require('braintree-web/client').create;
createClient({
authorization: CLIENT_AUTHORIZATION
}, function (createErr, clientInstance) {
// ...
});
Per Braintree's docs regarding generating a client Token,
If [the failOnDuplicatePaymentMethod] option is passed and the same payment method has already been
added to the Vault for any customer, the request will fail. This can
only be passed if a $customerId is passed as well. If the check fails,
this option will stop the Drop-in from returning a
$paymentMethodNonce. This option will be ignored for PayPal, Pay with
Venmo, Apple Pay, and Google Pay payment methods.

Can I use Feathers for a real-time site that uses data updated from external sources?

In the docs it states that Services only emit events when a Service method modifies data. This is the case in all examples I have seen, where a client modifies that data from the browser itself and it gets automatically updated in other clients (like a chat webapp). But what if my data is modified externally outside of Feathers? Will I be able to use Feathers so that the data is updated in all clients?
In my specific case my data is actually stored in a MongoDB database which gets updated externally and autonomously. I want my web application to use MongoDB Change Streams to listen to changes on the MongoDB database (I already know how to do this) and then I want Feathers to take care of sending updates to all my clients in real-time.
In the example chat app, this would be equivalent to having a bot that also writes messages directly to the database outside of Feathers, and this messages should also be broadcasted to clients in real-time.
Is my use-case a good fit for Feathers? Any hint on how should I approach it?
Watching changefeeds has been done for feathers-rethinkdb here. Something similar could be done for MongoDB but there are several challenges discussed in this issue.
If your MongoDB collection only gets updated externally you could also create a simple pass through service like this:
app.use('/feed/messages', {
async create(data) {
return data;
},
async remove(id) {
return { id };
},
async update(id, data) {
return data;
},
async patch(id, data) {
return data;
}
});
Which is then called by the changefeed watcher and will automatically take care of updating all the clients through its events.

Monitoring progress of extraction job of file in a bucket?

I want to monitor the progress of an extraction job of a file stored in a bucket.
I've gone through the Webhooks API documentation, and if I understood everything correctly, the events only work for files stored in a folder, so it can't be used with a bucket. Please correct me if I'm wrong.
So, besides polling the GET :urn/manifest endpoint in the Model Derivate API, and assuming the Webhooks API can't be used with a bucket, is there any other way to monitor the progress of an extraction job?
Thanks.
Webhook now supports the Model Derivative event extraction.finished. This type is exactly used in the scenario of translating model of the bucket.
This is a blog on the API. I copied it as a reference on SO:
https://forge.autodesk.com/blog/introducing-webhook-model-derivative-api
Webhook now supports the Model Derivative event extraction.finished, so your app can be notified when translation job finishes.
To use it, (1) create a hook specifying a scope.workflow:
{
"callbackUrl": "http://bf067e05.ngrok.io/callback",
"scope": {
"workflow": "my-workflow-id"
}
}
And (2) when posting a translation job, specify the misc.workflow:
{
"input": {
"urn":
"dXJuOmFkc2sub2JqZWN0czpv...."
},
"output": {
"formats": [{
"type": "obj"
}]
},
"misc": {
"workflow": "my-workflow-id"
}
}
With my test, the workflow can be guid of your WebHook.The post body from Forge will tell you which file is translated and its urn, location etc.
Hope it helps.