TFS 2015 Web Hook to Slack Integration - c#

I have got a requirement,
When a work item is created (and status -say In progress) in TFS 2015(not vsts), I want my web hook to fire a post method which ll create a Channel in Slack, and invite few folks.
2) Once the Bug is closed - read all the history of channel and push the history back to Bug.
I was able to achieve the same with TFS server side plugin and it's working, but requirement got changed to Web hooks.
Could someone help me on how to achieve custom web hook.which ll enable events from TFS WI to Slack please?
Thanks,

You can not create new incoming webhooks in slack programmatically, but you can use any existing incoming webhook for a new channel.
Just add the channel property in your message to the webhook.
Example from the Slack documentation:
curl -X POST \
--data-urlencode 'payload={"text": "This is posted to #general and comes from *monkey-bot*.", "channel": "#general", "link_names": 1, "username": "monkey-bot", "icon_emoji": ":monkey_face:"}' \
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
So to implement your requirement I suggest you create a new channel and invite users as needed through the Slack web API. And then use an existing incoming webhook to send messages to that channel.

TFS has default slack service hook which can post a message to a channel. The API looks like below:
POST http://tfsserver:8080/tfs/DefaultCollection/_apis/hooks/subscriptions?api-version=3.2
Content-Type: application/json
{
"consumerActionId":"postMessageToChannel",
"consumerId":"slack",
"consumerInputs":{
"url":"https://hooks.slack.com/services/xxxxxx"},
"eventType":"workitem.created",
"publisherId":"tfs",
"publisherInputs":{
"areaPath":"",
"workItemType":"",
"projectId":"77e3c775-dc30-4354-xxxx-xxxxxxxxxxxx"}
}
For your second requirement, you need to check Slack Api to see how to read all the history of channel, and use Update work items to update Bug work items.

Related

How to get new emails automatically using Microsoft Graph in a UWP app

I have successfully connected to Microsoft Graph using OAuth. I can receive and send emails from my Office365 account.
But I am completely stuck on how to receive emails automatically, similar to the IMAP IDLE routine.
I am referencing
using Microsoft.Graph;
using Microsoft.Toolkit.Services.MicrosoftGraph;
I have tried Subscription but have no clue what to do next, or even if this is correct.
Subscription sub = new Subscription {
ChangeType = "created",
NotificationUrl = "urn:ietf:wg:oauth:2.0:oob",
Resource = "/users/me/messages",
ExpirationDateTime = DateTimeOffset.Now.AddMinutes(20),
ClientState = "????" // if applicable, what is this
};
To make a subscription you need to expose a notification URL with https (see graph documentation).
POST https://graph.microsoft.com/v1.0/subscriptions
Content-Type: application/json
{
"changeType": "created,updated",
"notificationUrl": > "https://webhook.azurewebsites.net/notificationClient",
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": "2016-03-20T11:00:00.0000000Z",
"clientState": "SecretClientState"
}
If you want examples the graph documentation references a Node.js and asp.net example. Both use ngrok to expose an https URL (just for testing purposes though). The program tunnels HTTP requests through to your localhost (like a reverse proxy). If you have that setup, you have to validate your request. When you send your subscription request the first post message your notification URL will receive is a message with a validation token (see doc). You have to send this validation token back. Now you should receive notifications on your specified notification URL.
You can read about the Subscription resource type and its properties in the graph documentation.
For example, the client state is described as:
Specifies the value of the clientState property sent by the service in each notification. The maximum length is 255 characters. The client can check that the notification came from the service by comparing the value of the clientState property sent with the subscription with the value of the clientState property received with each notification.
Subscriptions are not in possible at this moment using Microsoft Graph for UWP, for notifications the Outlook 365 API should be used. The Microsoft graph api can be used for Auth and other tasks though.
Can Microsoft consider including streaming notifications in Microsoft Graph?

C# Bot framework - Resource not found Error

I've built a small basic web bot app using bot framework and want to deploy it on Azure. I've followed all the steps and it's working fine under "Test in Web Chat" of Azure Portal too, but however as I open my bot's endpoint
https://optlbot.azurewebsites.net/api/messages
I get an error saying
The requested resource does not support http method 'GET'
Can somebody please help me, I can't debug my application at all. I've also tested on emulator and there too it's working fine.
Yes, the URL https://optlbot.azurewebsites.net/api/messages works only for POST request and not a GET request, because you post a message from user to bot and not a get, you can see that in the MessagesController code.
Being said that, if you want to test your bot locally, you have to use the emulator. You can have a look at Bot emulator for the same.
Now if you want to publish the bot to the world so that others can see it and use it, so that's where the channel comes in. Consider channel as a medium by which you enable your bot for others to use with a much better user experience.
There are multiple channels available for the bot to be published in, and yes you can publish the same bot in all the channels.webchat is just one channel and the one which is enabled by default and the way to see it is :
Open your bot in the Azure Portal and click Channels blade.
Click Edit for the Web Chat channel
Under Secret keys, click Show for the first key
Copy the Secret key and the Embed code.
Click Done
So the embed code is actually an iframe which you can place in your website or share with others who want to use your bot. Or you can use the src of the iFrame too to reach the bot directly.
Again this is just one channel. You can take a look at the Configure channels documentation for steps to enable the bot in more channels like Skype, Microsoft Teams, Email, Facebook, Slack, Telegram, etc.
If you check the code of your MessagesController, you would find the following action defined in your controller, it only accept POST request and read the value of activity from the request body, it does not support http method 'GET'.
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}

Firebase - Send Notifications (Android)

I've an android app and need to implement push notification on it, send and receive simple notifications.
My scenario; When userY submit form about userX will send userX notification that userY sent you message...
My Question: Do I need to create server side layer (C#, PHP or Node.js) to handle this part, so from android send data to C# and C# send to Firebase ? or there simple way to do it direct from Android application ?
Thank you.
You do not need a server to send the message itself. You can even send from the bash shell.
curl -H "Content-Type: application/json " -H "Authorization: key=Your_AUTHKEY" -X POST -d '
{ "data" : { "mykey" : "myvalue"},"notification": {"title": "My test 1","body": "bla bla"}
, "to" : "Your_looong_TOKEN"}'
A problem may arise when passing a token. There can be a useful durability value (write to the base).
Just send a post request with the appropriate headers.
As per my comment, you should have a look at Cloud Functions for Firebase, specifically, Realtime Database Triggers.
Let's say you're using Firebase Realtime Database. For your flow where "userY sends a form to userX", it could go like there'd be a forms node for a users, where you'll add forms from other users, and every time a form is added, you send a notification with Firebase Cloud Messaging. Similar on how you'd send when using Firebase Admin.

Programmatically Schedule/Create Skype for Business Meeting

I am working on a C#/console application that will schedule Skype for Business meetings and have not been able to find a clear answer on what is possible and what is the correct approach / sdk to use for doing so.
The application needs to:
Create an lync / skype for business meeting at a future date with a single presenter who can bypass the lobby
Retrieve the URL for joining that meeting for use in an email invitation to the other participants (outside the organization)
This would be running against on office 365 instance of Skype for Business. I have found a dizzying amount of information regarding the subject here in various SDKs that may / may not apply:
Lync 2013 SDK
UCMA 4.0 SDK
Skype Web SDK
All seem to indicate they are not compatible with office 365 though, has anyone built a similar application or dealt with this before that could provide some advice?
You can create a meeting using the Skype for Business User API (UCWA), which is now available for Skype for Business Online (Office 365).
Specifically, you need to make a POST request to the "myOnlineMeetings" resource:
POST https://lyncweb.contoso.com/ucwa/oauth/v1/applications/103...740/onlineMeetings/myOnlineMeetings HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer cwt=AAEB...buHc
[...]
{
"attendanceAnnouncementsStatus":"Disabled",
"description":"hey guys let's do a musical!",
"subject":"holiday party",
"attendees":["sip:Chris#contoso.com","sip:Alex#contoso.com"],
"leaders":[]
}
In the response, you'll get a "joinURL" that you can give to participants:
HTTP/1.1 200 OK
[...]
{
"accessLevel":"SameEnterprise",
"entryExitAnnouncement":"Disabled",
"attendees":["sip:Chris#contoso.com","sip:Alex#contoso.com"],
"automaticLeaderAssignment":"Disabled",
"description":"hey guys let's do a musical!",
"expirationTime":"\/Date(136...000)\/",
"leaders":[],
"onlineMeetingId":"DED...367",
"onlineMeetingUri":"sip:Dana#contoso.com;gruu;opaque=app:conf:focus:id:DED...367",
"onlineMeetingRel":"myOnlineMeetings",
"organizerUri":"sip:Dana#contoso.com",
"phoneUserAdmission":"Disabled",
"lobbyBypassForPhoneUsers":"Disabled",
"subject":"holiday party",
"joinUrl":"https://meet.contoso.com/dana/DED...367","56de...4c83":"please pass this in a PUT request",
"_links":{
"self":{"href":"/ucwa/oauth/v1/applications/103...740/onlineMeetings/myOnlineMeetings/DEDX9367"},
"onlineMeetingExtensions":{"href":"/ucwa/oauth/v1/applications/103...740/onlineMeetings/myOnlineMeetings/DED...367/extensions"}
},
"rel":"myOnlineMeeting",
"etag":"891...351"
}
Note that the meeting doesn't have a scheduled time associated with it. It can be used at any time. You can of course place the URL in a calendar appointment (e.g. Outlook does this) but Skype for Business doesn't know about it.
Full details about the "myOnlineMeetings" request are here.
sched.lync.com
You have to rebuild the form request. This is the only way at this time.
We try the communication right now with java.

Facebook push notification

Im using Facebook C# SDK to post and fetch data. These simple tasks took forever to get running properly. Now I need to notify my webpage(ASP.NET C#) about changes on the specific facebook page so the webpage knows then it should fetch new data.
I have looked at this page : https://developers.facebook.com/docs/graph-api/real-time-updates/v2.2
But as usally with facebook documentations it misses to explain in detail how it works and how to get it working. Where exacly do I create the subscriptions? It says /{app-id}/subscriptions but I have tried this url with my app-id but no page is found?
I have tried to find examples on how to set this up but to no sucess.
Could someone please explain how this works? What do I need to do exacly to get this running?
Facebook subscription works by pinging a URL you own every time data has changed. You need to add a URL you own as a callback URL for Facebook subscriptions to work with
POST /v2.2/{app-id}/subscriptions HTTP/1.1
Host: graph.facebook.com
object=page
callback_url=http%3A%2F%2Fexample.com%2Fcallback%2F
fields=feed
verify_token=thisisaverifystring
In the above API request a POST request is made to add http://example.com/callback/ as the callback URL subscribing to the feed edges of the page object (a page object that the session user owns)
In your callback URL you must have it handle two actions
the initial callback (Handling Verification Requests via the verify token)
saving updated subscriptions (Receiving the Real Time Updates)
Here is an example of what it looks like in PHP
<?php
if ($_REQUEST['hub_verify_token'] === 'thisisaverifystring') {
echo $_REQUEST['hub_challenge'];
}
$file = 'sample.txt';
$inputJSON = json_decode(file_get_contents('php://input'));
file_put_contents($file, file_get_contents('php://input') );
?>

Categories