Import Hipchat into Microsoft Teams

I have come up with 2 “hacky” solutions to this. Both will require development experience and the use of Microsoft Visual Studio. The second method is by far more preferred, but I will still explain both just to give some additional ideas.

While this explanation is for Hipchat, it should work with any other platform that gives you a dump of their data.

Both methods I recommend creating a “Hipchat” user in O365 – I will explain why later.

First, you will need the Hipchat dump of your history. You can get this from the admin portal of their website. The dump will include all of the information for the rooms – if you want to also include personal messages you will need to contact their support and fill out a privacy form. The dump will consist of a zip file that contains directories (they represent your rooms) that each contain JSON files broken up by dates that contain your individual message objects. Using Visual Studio, I created an application that parsed the dump and created a collection of objects. The objects were pretty simple, just one that contained the room name and a collection of chat information (sender, date, message, file attachments, etc.).

Now that you’ve got your data parsed nicely, here is where you can import into Teams.

Method 1 (not preferred, requires manual creation of channels): Using Visual Studio, Selenium (browser automation) and Sharepoint libraries. Unfortunately, for private chats, this method would have to be used.

Using a browser driver, set your driver.Url to your teams channel URL. You can get this by going to Teams in a web browser, going into your specific channel and copying out the URL. I would set a breakpoint (I prefer to do this in debug mode, you could probably set a wait task for that class to appear or something similar but this was easier and let me monitor) after you navigate to the channel as you will need to authenticate. Here is where you would login as your newly created Hipchat user from O365. After that, let your code continue and you can locate the input by class name using something like this:

var f = driver.FindElementByClassName("cke_wysiwyg_div");

From there, you can use the Selenium SendKeys function to input your chats. Now, the reason I recommend creating a Hipchat user is because since there is no way to use impersonation here (AFAIK), each message will seem to originate from the “Hipchat” user – but, by using markup you can make it look like it appears from the original sender from your previously built objects using something like this and will be searchable:

String message = String.Format("*[{0}]* - [ _{1}_ ] - {2}", a.From, a.Date, a.Message);
f.SendKeys(message);
f.SendKeys(Keys.Return);

It will look something like:

[ John Doe ] – [ 2017-01-01 ] – Chat Message

For file attachments, you would need to programatically download them from the Hipchat URL (provided in the dump), upload to Sharepoint under your Channels documents and add that new link to your chat as a separate message while going through your chat objects.

Method 2 (preferred): Using Visual Studio, Microsoft Graph API and Sharepoint libraries. Drawback – cannot create private chats (yet!) – would need to use Method 1 for that.

You can utilize the Microsoft Graph API to not only create chat threads, but also channels. This will obviously be the way to go. Using their beta API (https://developer.microsoft.com/en-us/graph/docs/concepts/overview) you can create channels and chats.

You can use their rest services and post method for the following:

Create channel URL with JSON for channel name/description:
String.Format(@"https://graph.microsoft.com/beta/groups/{0}/channels", groupID);

Create chat within channel with JSON for chat message information:
String.Format("https://graph.microsoft.com/beta/groups/{0}/channels/{1}/chatthreads", groupID, channelID);

Instead of using the Teams markup, you would need to use HTML to format your chats so they look like they originate from someone else other than the user you are authenticating with and will look the same as the above example in Method 1. You can do this by setting the contenttype in your json with your message. You might be able to get away with just using plain text with markup from Method 1.

Same concept used for attachments as Method 1 using sharepoint libraries.

As mentioned previously, the drawback to this is that the MS graph API does not yet have the ability to create private chats. You would need to import using Method 1 for private 1:1 chats.

I hope this helps some of you. While it’s certainly hacky, you can create an application that will do this in a few hours and it will work. Until Microsoft provides a better way to accomplish chat platform migrations, this will do the trick, as it will for us. Everything will be searchable and function properly…

Let me know what you think.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s