Trying to return a Twilio call to a Studio Flow - twilio

There's a lot going on, but I think I've narrowed it down to something simple. I hope someone can provide any kind of guidance as to what in the world I'm doing wrong.
I've got javascript voice (2.0) working with node.js. I can call inbound and outbound, and I can send a call from a studio flow to a javascript client. This all works. The issue is that when a javascript client user presses "reject" (out of the box example code) or the call isn't answered, it's just dropped. It doesn't return to the studio flow, and I suppose it isn't designed to.
To fix this, I am trying to get the call using the example for client.calls(call sid).update, and I can take the call and issue Say commands and play mp3 files as shown in the example. But when I try to return the call to the studio flow using the webhook url (with or without ?FlowEvent=return appended) it fails. I've tried using the twiml: syntax and providing valid twiml, and I've tried using the url: syntax and providing a url that produces valid redirect twiml (using the echo twimlet).
The URL I'm using is https://webhooks.twilio.com/v1/Accounts/{my_account_sid_here}/Flows/{valid_flow_sid_here}?FlowEvent=return (with and without ?FlowEvent=return at the end)
twiml like this;
<Response><Redirect method="POST">https://webhooks.twilio.com/v1/Accounts/{my_account_sid_here}/Flows/{valid_flow_sid_here}?FlowEvent=return</Redirect></Response> (with and without ?FlowEvent=return at the end)
I'm using the Parent Call Sid (the call sid for the stream never does anything so I assume that isn't the one to use) and the call, when updated, results in a voice message that says "We're sorry, an application error has occurred." I don't know if that is coming from studio or the twilio call processor. If I use the example url with the rick roll mp3 it works.
I've checked the debug messages and they seem to indicate that the flow webhook URL is returning a 400 status code. The documentation says to "To retrieve the Studio Webhook URL in your Studio flow, click the red Trigger widget. The URL starting with https://webhooks.twilio.com/v1/... is the Webhook URL for this Flow" and that's where I got the URL which includes the account sid and flow sid, which I've also checked for correctness.
I'm not sure what to try next.

Related

Can a Twilio Studio widget run a function created under another account?

I have a studio flow set up under a Subaccount. I have a function created under the main account.
When I create a function widget in the subaccount studio flow, I don’t see the main account’s function listed.
I’ve also tried using the http request widget calling the function’s url, but studio shows an error saying that the url cannot be blank.
So is it possible to run a function under a different account with the Twilio Studio function widget?
Subaccounts are normally used to separate resources from each other. So a Twilio Function written in one account will not appear in another.
You could use the HTTP request widget to make a request to the Function by its URL, however that would only work if your Function is set to public visibility.
I’ve also tried using the http request widget calling the function’s url, but studio shows an error saying that the url cannot be blank.
If you've entered the URL of the function into the widget, the Studio HTTP request widget should be fine. If you are finding it is showing an error, something else might be wrong.
I would not recommend running cross account resources like this though. It breaks the separation of concerns that a subaccount gives you.
Instead, I would deploy the function code to your subaccount as well, and then hook it up as normal in the Studio Flow. That way, you always know that only work done within the Subaccount can affect its behaviour.

Twilio Studio HTTP request

I have been working with Twilio Studio trying to build this IVR tree. I need a few requests that will go back to my main platform to check the caller_id of the line calling in and to verify_employee pin etc after the caller_id is verified.
I know there is an HTTP request widget that I can use to hit the endpoints on the main platform. But I am running into the issue where it's validating the number that's inputed. The person calling in will get verified then have to enter the 3 provider pin and 4 employee number. Right now I can input anything and it will go through onto the next option. Anything I can do to validate the numbers against the endpoint? or maybe I am just doing my tree wrong.
Off of the trigger I am using a http request to check the caller id of the person calling in. Then using a gather input widget to gather the pin #'s then using that to call the verify employee http request.
Any thoughts would be appreciated. Thanks!
The Twilio Split Widget based on the http response (and one more
later, based on the user input for their code...) should do the job.

Asana Webhooks API

So I have implemented the Asana Webhooks API as described in their documents. I can pass it a project ID and request a new webhook be created. The API successfully sends a authentication request to my application which returns the Security header as described in the Docs. Asana then returns the expected success response, outlining the newly created Webhooks unique ID.
Now if i take this ID and then query the Asana API to show me all configured webhook's on either the parent Workspace or the project resource directly it returns an empty data JSON Object or reports the resource doesn't exist, suggesting the Webhook Ive just created wasn't actually created, despite giving me the expected success response.
Also If I then make a change to a project it doesn't fire the webhook and I don't receive any events on my application.
Strangely everything was working on Friday but today (Monday) I'm experiencing these issues.
Any pointers would be good, Ive been working as the Docs suggest in terms of my request structure and am authenticating using a PAT, Ive even tried a newly created token.
Thanks,
Our webhooks use the handshake mechanism to make sure that it's possible to call you back, but there's always the possibility that subsequent requests can fail. Additionally (although we don't document this very well - there's an opportunity for us) we should immediately try to deliver a (probably) empty event after the handshake (it looks like {"events":[]}. This is kind of like a "second callback" that contains anything that has changed since you created the webhook.
If this fails - or if any subsequent request fails often enough - the webhook will get trashed. "Failure" in this context means returns HTTP response codes other that 200 or 204.
As for why you're having trouble querying the webhook itself, I wasn't able to repro the issue, so we'd have to dive deeper. It should be fine if you:
Specify the workspace
Optionally specify the resource
I tested this out, and it seemed fine. You also might want to directly query the webhook by id with the /webhooks/:id endpoint - note to use the id of the webhook returned by create, and not the id in the resource field.
If you created the webhook (specifically, your PAT or OAuth app was the one making the create request) you should see the information just fine. If you can get the webhook by id, you should see last_failure_at and last_failure_content fields which would tell you why the webhook was unable to make the delivery.
Finally, if you would like to contact us at api-support#asana.com and let them know more details (for instance, the ID of the webhook you're trying to look at) we can look at those fields from our side to see if we can identify what's going on.

How can my slack custom command produce /remind me like links

I am writting a custom slack command that implements a
task manager like interface (I know ... there are many out there :-), mine interfaces with odesk/upwork to outsource my micro-tasks :-) ) .
Anyway, I like a lot how the /remind command included Complete Delete etc links in its output to facilitate subsequent interactions with the user that entered the command and I am trying to figure out how to do the same trick.
What I have thought so far is to include links in my output that are ... GET /slack-link?method=POST&token=xxx&team_id=xx&command=.. ie carry in their query string the complete json payload that slack would have produced from a normal custom command. slack-link acts as a "proxy" whose sole role is to submit a POST back to my normal slack endpoint. I can even reuse the same response_url for these command-links.
I have not tried it but I think these URLs will just open another window so that path wont exactly work...
Has anybody tried something like that before?
As you've learned, those are currently only available to built-in commands. However, as I was curious and wanted to know how those are done, I looked in the API and found out that the URLs are just formatted normally but have a special "protocol":
You asked me to remind you to “test”.
​_<slack-action://BSLACKBOT/reminders/complete/D01234567/1234//0/0/5678|Mark as complete>
or remind me later: <slack-action://BSLACKBOT/reminders/snooze/D01234567/1234//0/0/5678/15|15 mins> [...]
Clicking on such a link results in an API request to method chat.action, with the following parameters:
bot: BSLACKBOT
payload: reminders/complete/D01234567/1234//0/0/5678
token: xoxs-tokenhere-nowayiampostingithere
So it looks like those URLs have three parts:
<slack-action://BSLACKBOT/reminders/complete/[...]|Mark as complete>
slack-action://: the "protocol" like prefix to let Slack know this is a chat action URL.
BSLACKBOT: the bot which (who?) will receive the payload. Can only be a bot user and the ID must start with B, or the API request will fail with invalid_bot.
the rest of the URL: the payload that gets passed to the bot. It doesn't look like this is parsed nor handled specially by Slack.
This is actually not a new feature, since they used to have API URLs back in late 2013 or early 2014 (I don't remember precisely) which they removed for "security reasons".
It could be interesting to see if we can use chat actions with custom bots, and if so, what we could do with it.
I got the answer from Slack support:
In regard to your original question: currently Slack doesn't provide
the ability to embed 'action' links in our custom integrations. Only
built-in features like /remind can utilize these at the moment. For
external services, you'll need to link to a URL that opens in an
external web browser.
We do hope to provide a similar function for custom integrations in
the future, allowing for interactive messages.
Thanks,
Ben

Twilio returning a 500 internal server error when trying to obtain response from my web snippet

Ahoy!
I installed Twilio in Laravel and ran the code below at the routes (though also I reproduced it at the Controller using this same code in a function)
Now I dont have any issue with namespaces or trying to access the class as it gives no error when using the method against it.
The snippet is as simple as this:
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Services_Twilio_Twiml();
$twiml->say('Hello - your app just answered the phone. Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
So I got my phonenumber and went to the Twilio page and added to the URL to which the phone is bound the URL where this snippet is located
sort of www.maweb.con/incoming
I then ring the phone from the kitchen (this shouldn't make a difference lol) and then I get an email error from Twilion saying that when "they" went to that URL to retrieve information and that all they got was an Internal Server error 500.
I stuck my nose into the details of the error and I found this:
<abbr title="Illuminate\Session\TokenMismatchException">TokenMismatchException</abbr> in
I am familiar with that kind of errors, that happens also when you are trying to send a parameter via an Ajax snippet. You need to make an exception at the VerifyToken php file in the Middleware, but I cannot know what the parameter is now, since it must be using the Twiml library and god knows what's in there, it is a blackbox.
I haven't Required the twilio. I just installed it via composer, but like I said, it does recognize the class services_twilio_twlim now. The error is when trying to obtain a response when accessing to that URL.
For a Web not based on a framework I have included:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
require_once('twilio-php-master/Services/Twilio.php');
?>
<Response>
<Say>Hello Monkey</Say>
</Response>
So, here is something that I hope will help others when working with Twilio applications:
First of all Twilio is fantastic and I love it but one needs to know how to, of course, as with everything:
You need to know the critical importance between the coding scenarios: you may be working with a PHP framework or you may be coding native PHP and not using any MVC
If you are using Laravel, you will need to import the class by:
use Services_Twilio_Twiml;
and I assumme you have installed the Twilio class through Composer.
if you are not on a Framework just do the old require_once(path to your Twilio.php file) something like Twilio-php-master/Services/Twilio.php
Now, the issue that had me stuck for a while.
Even if you correctly enter the URL at your Twilio page and your telephone is correctly configured to point at it, if you are using Laravel, as Twilio sends its data through POST (by default) the Token Protection against XSS in Laravel will block it by means of the VerifyCSSR Middleware file.
Since you cannot see what values is Posting, you cannot add them to the exceptions and your application will never work.
Therefore, you need to send it via the URL query, that is, change it to HTTP GET.

Resources