I am currently trying to setup a slack bot in C# using azure. I am new to interacting with http requests in C#, and am having trouble getting the post request from slack to work. When I call my slash commands in slack, I am met with an http_client_error and no other error information. Does anyone have any resources they could point me towards about working with slack commands in c#. Any recent help would be much appreciated. I cannot program the bot in another language due to limitations of a dll I am using. I guess the main question I have is how to handle http post requests from slack in C#.
When you give slack the link that it needs to send the HTTP Post to, make sure you have https:// at the start of the link.
Related
I am trying to understand how to integrate BotFramework (C#) with an existing application without the use of Azure and using DirectLine, but everything I have seen so far requires an Azure subscription. I have looked at ngrok, but not sure if that is reliable for a production environment. I have also been digging around the source code repositories of BotFramework-Emulator and BotFramework-WebChat, but haven't found good information that relates to my use case.
If we have an existing "chat box", that has already been styled and has some basic commands that a user can enter, how could I reuse that chat box, but just implement the BotFramework routing? The idea being it is our standard chat box, but when the user types a command like /todo it would start a new bot conversation.
Without Azure, how would we generate a DirectLine token to access our C# WebAPI BotFramework Chatbot? I tried just opening a WebSocket in devtools to try and send messages, but wasn't successful
Sure, it is possible to just to plain REST routing, but would ideally like to use WebSocket to send/receive messages.
Generally speaking, the Azure Bot Service is a required component of using the Microsoft Bot Framework as it serves as the connector (via the supported channels - DirectLine, Teams, Slack, Facebook, etc.) between your bot and the specific channel. It is also responsible for generating the tokens that allows your bot to connect and pass messages around.
However, it is possible to run your bot without the use of the Azure Bot Service. Two options that may serve your needs are:
offline-directline: "Unofficial package to emulate the bot framework connector locally."
InDirectLine: "[T]he DirectLine is a bridge that connects your bot and your client. This project (InDirectLine) is a custom implementation of my own..."
You will need to research both to identify which, if either, could/would meet your needs. But, in short, both projects allow you to run your bot locally, or seemingly from a hosted remote environment, and connect to it.
Hope of help!
I have a c#-based program that can send messages and files to our SlackWorkspace via my SlackApp (I'm using HttpClient to communicate with Slack).
Now, to distribute this program in my workspace and to make it so that every user will have his own identity, it says that I have to use OAuth and create verification-tokens, specific for each user.
It says in the Slack-documentation I have to use a redirect-URL (as per docs) to my own server.
We have a server that I potentially could use for this. But I have never done anything like this before and I am unclear on what "answer" I have to provide from our server. I thought the verification-process would be handled by Slack.
Anyone has an idea on how to approach this?
And before anyone asks - yes we need to install it for everyone and make them identifiable as themselves. We can't use the "SlackApp" as user. :)
I would be very grateful for code examples(in c#) and explanations on how this whole redirect-thing is working.
Slack uses the standard Oauth 2.0 protocol to authenticate apps, similar to Google and Facebook.
So the "verification-process" is indeed mostly handled by Slack (as outlined here), but your Slack app needs to initiate it and handle the responses properly. Also its a multi-step process and includes the user having to login into Slack with their credentials. This why you need a web app to handle the whole process.
To enable a Slack app to generate tokens via Oauth a web app is needed:
can be reached from the Internet
able to handle HTTP requests like a web server
has persistent storage for the newly generated tokens
This is probably easier to implement with ASP.NET Web Pages, which can utilize many functions from an existing web server.
But for this answer, lets look on an implementation in .NET Core. For that we need to create our own web server and some rudimentary session handling. Main concepts include:
HttpListener class for providing fundamental ability to listen and respond to HTTP requests
Handle multiple requests in parallel
Cookies / Session handling
MD5 hashes
The details go a bit beyond the scope of one answer. But I am happy to share a working example implementation on this GitHubGist.
Btw: For the local development of such a web app its recommend to use a VPN tunnel like ngrok, that allows one to expose a local machine securely to the Internet and Slack.
I read the OneNote Api Documentation https://dev.onenote.com/docs
But I don´t understand how to make a request to the OneNote API with c# web application in order to get all the pages in my OneNote.
I already got the Application Id, Application Secret Id and Redirect URL, but i don´t know where do I have to use them, because I have never done and http request and the documentation only provide the following: https://www.onenote.com/api/v1.0/me/notes/pages, so I don´t know how to send the id´s, redirect url and Authorization: Bearer.
Could you provide me the specific code to get a successful connection to OneNote API using Application Id, Application Secret Id and Redirect URL.
And the code structure to make a http request in order to get all the pages, notebooks, etc
I would appreciate if you could help me with this.
I would recommend using Microsoft Graph instead of the standalone OneNote API. Microsoft Graph includes support for OneNote. There is also an SDK for .NET available. There are also code samples for ASP.NET, UWP and Xamarin.
Before you can use the Graph API (or most any REST API for that matter), you will need to obtain an authorization token (i.e. the bearer token you referred to in your question). There are libraries available for simplifying this process. Behind the scenes, these libraries are executing an OAUTH 2.0 flow. You can read about what is going on under the covers here.
I believe the link they have on the OneNote Dev page is broken. The team has put together a public repository that contains a bunch of sample code in a myriad of languages including C#.
This is the main repo
Web API (ASP.NET Core) Repo
I believe the easiest way to understand these concepts is to look at sample code that does authentication. I recommend this sample:
https://github.com/OneNoteDev/MsGraph_OneNoteApiSampleAspNetCore
Btw - the demo is here: https://onenoteapisamplegraph.azurewebsites.net
Thank you everyone I have Checked all the links that you provided me and they were very useful, I did a connection to Microsoft Graph with the authorization token and I got access to my OneNote pages.
Thank you for your help.
I'm starting a side project that will integrate heavily with Facebook. I'm going to use React in the front-end and it will talk to a REST ws made with asp.net core web api.
The idea is that in this API I will make the calls to Facebook.
Basically, I want to: login, get/post messages from Messenger, get/post comments and messages from a business page.
I googled a little and didn't find many resources or examples of how to do this integrations other than the Facebook documentation, that has a lot of stuff and I don't know very well where to look.
I also found this SDK for .NET but it looks a bit dated https://github.com/facebook-csharp-sdk/facebook-csharp-sdk and
So, my question is: Is reading the documentations entirely really the best solution?
If anyone could at least give me a hint where to go I'd be really thankful. Would it be better/easier to integrate with Facebook with other stack than c#/asp.net?
Also, if there's any other API, SDK or something already built in .NET that would help with that I'd be grateful.
Thanks in advance.
I am one of .net developers working with Facebook API more then 5 years and we have tried to use "Facebook SDK for C#". It has more issues then benefits. In result we end up with our own small Facebook API client. Basically it is just a "RestSharp" HTTP library, "Newtonsoft.Json" for serialization/deserialization and couple of generic functions where you supply Facebook API endpoint, and specify what class you expect back as generic parameter.
var accounts = client.Get<Accounts>("me/accounts");
var createResponse = client.Post<CreateResponse>("123456779/feed", postToCreate);
Facebook SDK for C# works great for standard .NET
https://hackerapp.com/net/
https://github.com/facebook-csharp-sdk/facebook-csharp-sdk
As for .NET Core I think you are out of luck at the moment. Unless you want to port it to .NET Core yourself.
Automated Customer Service bots are not uncommon in FB, but code is hard to find. I assume you had setup you App's domain and got it reviewed and approved by FB.
I tried to set a chat-bot with both, python and .NET, and I must say the python Api is much more complete, quick, and less buggy than the C# one. But, as far as I know, only the PyApi has integrated reactions (haven't tried them).
Therefore, you will need to do this manually by using the Facebook Api by sending direct GET/POST request triggered by your ASP.NET, or use some kind of inter-language platform such as IronPython to workaround the problem (which basically assembly the call, add the Key and secret, and CURL-it).
As final remark (not a very motivating one), there is documentation for post reactions, but not for message as you can see here (posts), and here (messenger).
You can perform a lot of the facebook operations on the client side using their javascript SDK.
https://developers.facebook.com/docs/javascript
In regards to getting up to speed on server side API calls from .NET you can check out the facebook graph api explorer. It can be helpful for discovery.
https://developers.facebook.com/tools/explorer/
In case someone is looking for this topic, I had the same needs myself. After not finding a Facebook SDK to use with .NET Core, I've created a new open source .NET Standard unofficial SDK for Facebook: https://github.com/developer82/FacebookCore
I'd like to capture webhooks from GitHub (for various events, like commits, etc), from my C# console application. I figured I could "listen" to an endpoint and webhooks would be thrown there, but it seems that perhaps github is actually sending webhooks to endpoints that you need to setup and listen from.
If the latter is this case, then I suppose I'll need to setup a web server to capture the webhooks. If the former is the case, then I'm not finding in the docs how I can listen for webhooks from GitHub?
Your question isn't very clear, but I think you're on the right track vis-a-vis implementing a web server. So, my answer to your question is: you need to implement a web server to receive the webhook requests.
Edit
At the bottom of this document, you will find instructions on how to implement a very simple web server (in Ruby) to receive GitLab webhook requests. I know this isn't a turnkey solution for you, but hopefully it will help get you going.