Directline 3.0 API, StreamUrl with ClientWebSocket - c#

I creating a bot connector using Directline 3.0 API. After starting a new Conversation using DirectlineClient object, I get the StreamUrl. How can I use it to communicate with the Bot? I tried one sample given here.(http://itq.nl/net-4-5-websocket-client-without-a-browser/) but it does not work. #botframework

A new sample using C# + DirectLine v3.0 + WebSockets is currently under review and will soon be merged into the BotBuilder-samples repository.
Take a look to this Pull Request to see the code of the new sample.

Related

Azure SignalR .NET Framework C# Client cannot authenticate

I am trying to connect a C# .NET 4.7 application as a client to my Azure SignalR service. I am using the ASP.NET version of the SignalR client library, NOT the ASP.NET CORE version.
I have code set up like this:
var serviceUtils = new ServiceUtils(ConfigurationManager.ConnectionStrings["Azure:SignalR:ConnectionString"].ConnectionString);
var url = $"{utils.Endpoint}/client/";
_connection = new HubConnection(url, $"?hub={hubName}")
{
ConnectionToken = serviceUtils.GenerateAccessToken(url, userId)
};
IHubProxy proxy = _connection.CreateHubProxy(hubName);
await _connection.Start().ConfigureAwait(false);
However, this does not work. I get back a 'StatusCode: 401, ReasonPhrase: 'Unauthorized'' when _connection.Start() throws an exception.
The "ServiceUtils" token generation is pulled from the example here:
https://github.com/vavjeeva/AzureSignalRConsoleApp/blob/master/AzureSignalRConsoleApp.Utils/ServiceUtils.cs
Interestingly, I have implemented the same logic in a basic C# .Net Core console app, using the .Net Core version of the library, and it actually does work, using the same connection string. The difference is I am using the HubConnectionBuilder, which does not exist in the asp.net version of the library. My assumption is that the two are authenticating in different ways.
How do I get this sort of functionality working in this version of the library? I want my service application, as a client, to be able to invoke hubu methods via the Azure SignalR Service.

How to specify the API version?

According to the Azure DevOps Services REST API Reference, the request URI has the following format:
https://{instance}[/{team-project}]/_apis[/{area}]/{resource}?api-version={version}
Regarding the api-version:
Every API request should include an api-version to avoid having your app or service break as APIs evolve.
I started using the .NET client libraries for Azure DevOps Services (and TFS) to manage dashboards programmatically.
I am able to connect to Azure DevOps using a Personal Access Token:
var credential = new VssBasicCredential(string.Empty, "PersonalAccessToken");
using (VssConnection connection = new VssConnection(new Uri("...."), credential))
using (var client = connection.GetClient<DashboardHttpClient>())
{
// ...
}
How can I specify the API version? Does it still make sense to do it, when using the .NET client libraries?
The API version is decided by the client libraries. You can confirm this by disassembling them (e.g. using ILSpy).
For example, in the current stable release of Microsoft.TeamFoundationServer.Client, DashboardHttpClientBase has a CreateDashboardAsnc method that makes the following call:
this.SendAsync<Dashboard>(..., new ApiResourceVersion("4.1-preview.2"), ...);

Sending an email with SendGrid API from ASP.Net Framework 3.5

I'm trying to send an email using SendGrid API with an API Key I already have.
The problem is: I have to do this from an old .net application, whose asp.net framework version is 3.5 (and changing framework version is not an option)
I'm failing to find useful information on how to achieve it. The only code I found makes use of SendGrid csharp libraries, and these do not support asp.net framework 3.5
This is the code sample I found here, but I cannot make this work from my .net 3.5 web app:
// using SendGrid's C# Library - https://github.com/sendgrid/sendgrid-csharp
using System.Net.Http;
using System.Net.Mail;
var myMessage = new SendGrid.SendGridMessage();
myMessage.AddTo("test#sendgrid.com");
myMessage.From = new MailAddress("you#youremail.com", "First Last");
myMessage.Subject = "Sending with SendGrid is Fun";
myMessage.Text = "and easy to do anywhere, even with C#";
var transportWeb = new SendGrid.Web("SENDGRID_APIKEY");
transportWeb.DeliverAsync(myMessage);
// NOTE: If you're developing a Console Application, use the following so that the API call has time to complete
// transportWeb.DeliverAsync(myMessage).Wait();
Any ideas?
You have a couple of options. The SendGrid API uses the HttpClient class to make the requests and this requires the .NET 4+ dependency.
You could try implementing your own implementation using RestSharp, this is compatible with .NET 3.5 and the SendGrid API uses an interface you can implement. It would just need to be adjusted from the source code on github.
Use the .Net SMTP classes to send your emails and configure as per the guidelines in the SendGrid documentation.
Proxy the requests via another WebAPI that is running .NET 4+ and simplify what is required to make these calls by implementing your own API. Use something like the WebClient class or RestSharp to make the calls.
** Scrap that, option 1 is harder than it looked **
That the ISendGridClient is a bit of a weird example. It used the implementation inside of the interface for some parameters. Looks like 2 and 3 are good options!

how to use pragrammable chat of twilio in c#

can enyone help me out to undersatnd this Here's a link! how to use in c#
i want to know how to use it
how to use pragrammable chat of twilio in c#
var client = new TwilioIpMessagingClient(accountSid, authToken);
Message message = client.CreateMessage(serviceSid, channelSid, memberSid, body);
Console.WriteLine(message);
https://www.twilio.com/docs/api/chat/rest/messages#action-create
Twilio developer evangelist here.
There is a full tutorial for using Twilio Programmable Chat from C# right here.
You might also find that the Chat fundamentals documentation will help. The key is that you need to run a server which you can use to generate an access token for your users so that they can access the Chat service. Once you have done that, you can build the rest of the application in the front end. You can also perform actions from C# using the REST API.

What are the available functions to send notifications to a Facebook user?

Currently I am using Codeplex's Facebook Developer Toolkit version 2 for my ASP.net Facebook application. I would like to be able to send notifications to a user's Inbox or wall of the application and was wondering what are the available functions to do that? If not in the API, then please provide example functions from the main Facebook library. This will help immensely. Thanks!
After a brief search I found an example of sending notifications using the toolkit:
facebook.Components.FacebookService fs
= new facebook.Components.FacebookService();
fs.ApplicationKey =
ConfigurationManager.AppSettings["APIKey"];
fs.Secret =
ConfigurationManager.AppSettings["Secret"];
string sessionKey =
dict["facebook_session_key"];
fs.SessionKey = sessionKey; fs.uid =
long.Parse(member.FacebookId);
fs.notifications.send(member.FacebookId,
"notification message");
(from: http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=49876)
After looking through the Codeplex source it's clear that this sends a user-to-user notification, and therefore requires an active user session of the sender.
Codeplex does not appear to support app-to-user notifications which do not require a session, but adding this feature would be trivial. Add a type variable to the send method and set it accordingly based on the API documentation here: http://wiki.developers.facebook.com/index.php/Notifications.send
The source code for the notifications.send method in the Codeplex Developer Toolkit is here:
http://facebooktoolkit.codeplex.com/SourceControl/changeset/view/28656#233852
Please keep in mind that the Codeplex developer toolkit source code has not been updated in over 3 months. This means that it does not support many new Facebook API features and changes. You may want to browse the client library wiki page to find a library that is more up to date: http://wiki.developers.facebook.com/index.php/Client_Libraries

Categories