'Scroll Chat Window in Microsoft Teams
I am trying to make an application that would allow me to copy a chat(archive) from "Microsoft Teams".
I used SPY++ to get window handles and then I used WIN32 Calls in my program to get the same handles
foreach (Process process in Process.GetProcesses())
{
if (process.MainWindowTitle.Contains("Microsoft Teams"))
{
IntPtr hwnd = process.MainWindowHandle;
EnumChildWindows(hwnd, callBackPtr, windowHandles);
StringBuilder sb = new(length);
foreach (object childHwnd in windowHandles)
{
GetClassName((IntPtr)childHwnd, sb, sb.Capacity);
if (sb.ToString().Contains("D3D", StringComparison.CurrentCultureIgnoreCase))
{
teamsChatWindowHwnd = (IntPtr)childHwnd;
break;
}
}
}
Then I wanted to use SendKeys to send the mouse scroll to scroll up to the earliest message. I haven't completely figured out how I will be able to tell but this is a step-by-step process.
The SendMessage code
RECT rect;
GetClientRect(teamsChatWindowHwnd, out rect);
Point p = new Point(500, 500);
for (int i = 0; i < 100; i++)
SendMessage(teamsChatWindowHwnd, WM_MOUSEWHEEL, -120 << 16, ref p);
I've tried different versions of SendMessage and I also tested this on a notepad window. The notepad window with SPY++ I can see the messages being sent. With Teams I cannot see any messages being sent. The teams window is Class: Intermediate D3D window.
I've also Googled to try and find a similar application or anything but, there doesn't appear to be any apps out there that do this. You have to be the ADMIN for most of the archiving methods. There was a couple attempts to do it in the Web Version and none of them seem to work for me either.
Solution 1:[1]
There are 2 ways to read the chat messages in Teams.
You can read the chat messages using Graph API: https://docs.microsoft.com/en-us/graph/api/chat-get?view=graph-rest-1.0&tabs=http
You can use message action based Messaging Extension: https://docs.microsoft.com/en-us/microsoftteams/platform/resources/messaging-extension-v3/create-extensions?tabs=typescript#initiate-actions-from-messages
You can refer below sample: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/51.teams-messaging-extensions-action
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dharman |