Twilio making call using Dll version 5.3 - c#

If we Use the Url as per the Sample Code,it works fine.Here is the Url Used in sample code : ("http://demo.twilio.com/docs/voice.xml")
As per the Old Twilio Dll version 3.4 Were making Use of the twimlet Echo to make call i.e("http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E"));
And i want to to create to create Stateless apploication,Without application Hosting in any server.
The twimlet echo Url is working fine in version 3.4 and the same URL is not working in 5.3.
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "909dajhdusa78798324ndkjsahd";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+919000000000");
var from = new PhoneNumber("+919000000000");
var call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=test")); //Not working
call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=<Response><Say>testing</Say></Response>"));//Not working
call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E"));//Not working
Console.WriteLine(call.Sid);

Related

RestSharp 106.xx client can invoke HttpPut with variable string array service as version 108.xx

Server code:
Rest2ful service entry point is:
[HttpPut("exec/command")] public async Task<IActionResult> ExecCommand(string command, params string[] args) { Log.Information($"URL requested: {ControllerContext.HttpContext.Request.GetDisplayUrl()}"); ...... }
client code:
string body;
string restful_path = #"/motors/6";
string cmd = "find";
var request2 = new RestRequest(
resource: $"{restful_path}/exec/command?command={cmd}",
method: Method.PUT);
request2.AddHeader("Content-Type", "application/json");
body = new string\[\] { "abc", "Jeff", "some" };
request2.AddParameter("application/json", body, ParameterType.);
var response = restClient.Execute(request2);
Above code snippet (I referred sample code on the web) can invoke restful service -- ExecCommand() successfully when I install RestSharp 108.xx. But our team project still use RestSharp 106.11.4, Same code can NOT invoke that service.(server is always running, not version difference issue).
Have some experts guide to invoke this service with RestSharp on version 106.11.4
I tried same code on different RestSharp versions, result is different. But I have found sample code for version 106.11.4.

Trigger cancellation of Azure build pipeline from code from c#

I'm building an azure function that works as a approval checker for azure builds to be deployed, in the image below, you can see how it's being called for a pipeline that is trying to deploy.
What I need to do in C#, in some scenarios, is to CANCEL the pipeline that is calling my function to stop it from calling.
What I'm thinking to use is a PATCH method that Azure itself uses to cancel them, but I don't know how to call it with the proper headers and payload
This is what gets called when you hit the CANCEL button in a pipeline:
I'm building a request with a HTTPClient with this address, what else should I send as a param or header to make it work?
var _baseAddress = new Uri("https://dev.azure.com/myprojectname/");
var msg = new HttpRequestMessage(HttpMethod.Patch, new Uri(_baseAddress, $"{myProjectId}/_apis/build/builds/{buildRunId}"));
var serializedDoc = JsonConvert.SerializeObject(new { status = 4 });
msg.Content = new StringContent(serializedDoc, Encoding.UTF8);
msg.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
msg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json-patch+json");
var result = await _httpClient.SendAsync(msg);
I could not find any other similar question or implementation, so any answer is welcome

AWS API Gateway - Call GET Method with C# SDK

I have an API Gateway that uses IAM authorization. I have a C# application that I'm hoping to call the API with. I started with a GetMethodRequest but I don't see anyway to set the PathPart parameter.
var userId = _remoteCredentials.UserId;
var key = _remoteCredentials.Key;
var client = new AmazonAPIGatewayClient(userId, key, Amazon.RegionEndpoint.USEast2);
GetMethodRequest getMethodRequest = new GetMethodRequest();
getMethodRequest.HttpMethod = HttpMethod.Get.ToString();
getMethodRequest.ResourceId = "4abcde";
getMethodRequest.RestApiId = "aasfasdfs";
var task = Task.Run(async () => await client.GetMethodAsync(getMethodRequest).ConfigureAwait(false));
I was expecting something like the Test-AGInvokeMethod in the Powershell SDK which allows me to set the query string and the path.
$response = Test-AGInvokeMethod
-RestApiId aasfasdfs
-ResourceId 4abcde
-HttpMethod GET
-PathWithQueryString '/etl/upload_url'
Any help is greatly appreciated.
EDIT Below is something of a solution that I ended up using the AWS4RequestSigner is a library that I found on Github
var signer = new AWS4RequestSigner(userId, key);
var destinationUrl = string.Format("https://ad9vxabc123.execute-api.us-east-2.amazonaws.com/dev/etl/summary/latest?tms_id={0}&model_id={1}", _tmsId, _modelId);
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(destinationUrl),
};
var signed = Task.Run(async () => await signer.Sign(request, "execute-api", "us-east-2").ConfigureAwait(false));
var signedResult = signed.Result;
The AmazonAPIGatewayClient is for managing your API Gateway e.g. adding new stages or deleting API keys.
You're looking to invoke a method on your API Gateway, like Test-AGInvokeMethod does.
To invoke your API gateway, you need to call the deployed API endpoint using a HTTP client.
.NET's in-built HttpClient is a good start.

Passing parameters to a Twilio via CallResource.CreateAsync to programmatically add a bot to a conference call

I'm trying to create a conference call with a Moderator and several participants one of which is a bot.
The bot is controlled by the Moderator via a back channel so it can Say things etc to the conference call.
I setup the conference call when the Moderator calls in from a web client and then dial in the other participants and the bot using CallResource.CreateAsync with a callback url so I know which conference to add them to.
The bot needs to get a parameter so it knows which moderator to listen to for instructions.
However, I can't seem to pass any parameters to the bot (which is currently being triggered via another TwiML app) from the C# API using CallResource.CreateAsync.
Adding a participant to the call (callbackUrl adds the connected call to the conference) - this works fine:
var to = new PhoneNumber(callData.PhoneNumber);
var from = new PhoneNumber(_twilioSettings.PhoneNumber);
var callbackUrl = GetConnectConferenceUrl(callData.CallToken);
var url = new Uri(callbackUrl);
var participantCallResource = await CallResource.CreateAsync(to, from, url: url);
Adding the bot to call (Phone number is setup in Twilio as a TwiML app with a webhook back to my server) - how do I pass parameters to the TwiML app?
var toBot = new PhoneNumber(botNumber);
var fromBot = new PhoneNumber(_twilioSettings.PhoneNumber);
var botCallbackUrl = GetConnectConferenceUrl(callData.CallToken, isBot: true);
var botUrl = new Uri(botCallbackUrl);
var botCallResource = await CallResource.CreateAsync(toBot, fromBot, url: botUrl)
How do I pass parameters to a TwiML bin or Webhook or phonenumber from C#?
Do I need to add the bot in to the call a different way?
Parameters are passed either on the To or on the Url per https://www.twilio.com/docs/voice/how-share-information-between-your-applications
I believe your use case would put it on the Url. Assuming you have a moderatorId:
var botCallbackUrl = GetConnectConferenceUrl(callData.CallToken, isBot: true, moderatorId);
var botUrl = new Uri(botCallbackUrl);
where GetConnectConferenceUrl adds the parameter you need.
I've used it on the To line for a Client endpoint, so that looked like
var toBot = $"{new PhoneNumber(botNumber)}?moderatorId={moderatorId}";

Using netflixroulette API not working on Xamarin.Forms Based Android APP

When i am making call to netflix api (https://netflixroulette.net/api/api.php?actor=Richard) in Xamarin.Forms for Android. it gives error like "Java.Net.UnknownHostException: Unable to resolve host "netflixroulette.net": No address associated with hostname" but for other api's its working fine.
private string url = "https://netflixroulette.net/api/api.php?actor=";
private HttpClient _client = new HttpClient(new NativeMessageHandler());
var content = await _client.GetStringAsync(url + e.NewTextValue);
var movies = JsonConvert.DeserializeObject<List<Movie>>(content);
lst.ItemsSource = movies;
I am using these packages
Microsoft.Bcl.Build, Microsoft.Net.Http, Newtonsoft.Json, modernhttpclient
You have an invalid character (fl) in your URL:
Wrong:
https://netflixroulette.net/api/api.php?actor=Richard
Correct:
https://netflixroulette.net/api/api.php?actor=Richard

Categories