Paltalk beta version supports programmers to create bots ( Paltalk NG )

489 views
Skip to first unread message

VN

unread,
May 24, 2023, 9:00:20 AM5/24/23
to Programmers

This topic was created to help programmers, solve problems in creating bots for new paltalk.
Please describe the errors you have encountered, and what you want to be created in the next version of paltalk.
Download beta version, 1.29.89332: https://downloads.paltalk.com/download/beta/PaltalkSetup.exe

The answer from the paltalk development team:

>1. I need some way of sending text into the room. I can place text into “ui::controls::EmojiTextEdit”, but I don’t see >any way of sending that text into the room other than to send a newline character to the entire Paltalk application, >which isn’t ideal. Perhaps the “Invoke” of that automation element could send the line into the room.

This can be done using Win API on our latest build 1.29.0.89332.
1. Find “DlgGroupChat Window Class” window handler, FindWindowW can be used.
2. Find “RichEdit20W” window handler in the children list. EnumChildWindows can be used.
3. Send WM_SETTEXT message using SendMessage function to send a message to the room.

>2. I need some way of reading who is on mic. Nowhere in the Talking Now/Mic Queue/Chatting column of users does it show >the name of the user, for example not shown in “ui::widgets::UsernameWidget”

This also can be done using Win API on our latest build 1.29.0.89332.
1. Find “DlgGroupChat Window Class” window handler, FindWindowW can be used.
2. Find “SysHeader32” window handler in the children list. EnumChildWindows can be used.
3. Send LVM_GETITEMCOUNT message using SendMessage function to get room users count.
4. Send LVM_GETITEMW message with the LVITEMW pointer for the each user index using SendMessage function to get room member mic status. LVITEMW::iImage will contains 10 if the mic is on.
5. Send LVM_GETITEMTEXTA message for the each user index using SendMessage function to get room member nickname.

>3. emoji support. This is relatively minor, but limiting. Some emoji don’t show up in UI Automation elements. For >example, I can enter into the room and it won’t show up in QTextBrowser. QTextBrowser says there is a character >there, but it won’t show it and it isn’t in the text that I grab from that automation element.

We’ll try to resolve this issue in the future.
_____________________________________

Resolved: ( problem send text in room )

import win32gui, win32con hwnd_send = 0 room_list = [] def init_room_list_cb(hwnd, lparam): name = win32gui.GetClassName(hwnd) if name == "DlgGroupChat Window Class": global room_list room_list.append(win32gui.GetWindowText(hwnd)) def init_room_list(): win32gui.EnumWindows(init_room_list_cb, 0) if not room_list: print("No rooms found") def dlg_group_chat_cb(hwnd, lparam): name = win32gui.GetClassName(hwnd) global hwnd_send if name == "RichEdit20W": hwnd_send = hwnd def init_room_hwnd(room_name): window = win32gui.FindWindow("DlgGroupChat Window Class", room_name) win32gui.EnumChildWindows(window, dlg_group_chat_cb, 0) def send_text(text): win32gui.SendMessage(hwnd_send, win32con.WM_SETTEXT, 0, text.encode('ascii')) if __name__ == '__main__': init_room_list() print("Rooms:", room_list) init_room_hwnd(room_list[0]) send_text("Connected to the room: " + room_list[0])


or download file : paltalk_bot_example.py

paltalk_bot_example.py

Chicago David

unread,
May 24, 2023, 4:46:26 PM5/24/23
to Programmers
If possible, I'd like to see an example in C# (I use VB, but I can translate to it from C#).

My question to the dev team is have they ever gotten that code to work? I've tried similar code and when I try to send text into the room using that method I only get the first character of the string to show up in the room. So either I'm doing something wrong with the WM_SETTEXT or it doesn't work at all. Meanwhile, I currently use UIAutomation to send Unicode and ASCII to the type-in window. That is satisfactory except for sending the Enter key which I send to the room window. I last tried this in the Beta mentioned before and in the current release of 1.29.1.90567.

Also, I don't do Python, but it seems to me the example code above would fail because there is no Enter key sent after the WM_SETTEXT.

Lastly, when I use SPY++ I see 3  RichEdit20W controls. I'm not sure what the other 2 do, but I use the first one I find.

VN

unread,
May 25, 2023, 5:18:00 PM5/25/23
to Programmers
Here is an example of sending a message in C# in the attachment.
>I only get the first character of the string to show up in the room
Could you please take a look at the example. There is an important EntryPoint parameter in the DllImport expression:
[DllImport("user32", EntryPoint = "SendMessageW")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, String lParam);


> Also, I don't do Python, but it seems to me the example code above would fail because there is no Enter key sent after the WM_SETTEXT.
Please keep in mind that Paltalk does not expect the enter key event. We only listen WM_SETTEXT event and it is enough to send a message to the room.
Program.cs

Chicago David

unread,
May 26, 2023, 5:16:27 PM5/26/23
to Programmers
1. Thanks for that information about WM_SETTEXT not needing Enter. And thanks for the C# example, which helped a lot. I found that your definition of SendMessage worked whereas mine just printed the first character in the string. I didn't mention SendMessageW in my definition as I thought that was figured out automatically and none of the examples in https://www.pinvoke.net/default.aspx/user32.sendmessage use it. I had used one of the definitions in pinvoke.net.

However, my program has 2 modes, one that uses unicode characters and the other that doesn't. When I tried sending a unicode character using SendMessage 
e.g.
  SendMessage(editHndl, WM_SETTEXT, IntPtr.Zero, "😴This is a test")
it showed up as 2 question marks in the room
??This is a test

Does this method of sending to the room only work with ASCII characters?

2. I really really would like to read who is on mic. Considering my initial attempt failed (I was able to read how many were in the room, but unable to see information on any users) and seeing that my SendMessage definition was wrong, if you have a similar sample problem that is able to read one element in the user list at least, that would help. Also I'd like to use this in a room that has 100-150 people in the room, so iterating through that a couple times a second, or even once a second, is not the ideal. But if that is the only way of detecting who is on Mic I guess it would have to do. I can use UIAutomation to find the boundingrectangle of the name on mic.

And once that works I'd like to read who is 'in queue', which I assume is another property of the items. 

(And by the way, the queue seems to be manipulated and kept local to the client, which means in a room with lots of people going in and out of the queue it regularly gets screwed up. As an admin I have to rejoin the room every couple of minutes to make sure I have the accurate picture of the Queue. I wish this was fixed someday - it has been a problem for many months.)

Chicago David

unread,
May 29, 2023, 12:59:18 AM5/29/23
to Programmers
Also, is there any way of reading the content of the room using the old method of reading lines in a richtextbox? I see a recent Paltalk blog announcement that welcome/trivia bots of old supposedly work in the new paltalk, but for them to work there would have to be a method of reading lines in the room. It is hard to know what is available as the only program that shows these legacy controls is SPY++ and it shows very little.
Message has been deleted

Chicago David

unread,
Jun 1, 2023, 11:19:53 PM6/1/23
to Programmers

I use UIAutomation to read the chat room. I’m including a vb.net solution that finds the room and reads all the chat lines in the room – a bare bones program to illustrate some errors I see.

I get some serious errors in my bot that stops it at some point that I cannot replicate with my sample program. However the sample program demonstrates the following errors.

1. Most of my errors are with the UIAutomation call FindAll, which gets all children of the header of the chat lines. Sometimes it fails every couple of minutes and sometimes it might take a half hour or so. Below are some examples printed out by my test program. The part in bold is the e.Message text.

e.g.

Error in FindAll Pattern not found(08:02PM)

Error in FindAll Error HRESULT E_FAIL has been returned from a call to a COM component.(08:04PM)

2. In my test program I used UIAutomation to find the room AutomationElement (In practice I use the FindWIndow Win32 call). That also fails in the sense it returns NULL sometimes.

windowEle is Nothing (08:48PM)

3. I use FindFirst to find the header AutomationElement of the lines to read. I occasionally get an error there.

Error Finding Room Lines Position Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))(05:07AM)

---------------------------------------------

So I can run this test program in a room for 12 hours and get all these errors. I don’t know how UIAutomation works on the server side, but if it could be made more responsive to 3rd party programs that might help with bots.

I’m enclosing my test program. I start it, go into a chat room, type the name in “Room Name”, press Start, and then wait minutes or a half hour for the first error to appear in the Errors text box.

 "Starting error test at: (02:22AM)

Error in FindAll Error HRESULT E_FAIL has been returned from a call to a COM component.(02:53AM)
windowEle is Nothing (03:00AM)
windowEle is Nothing (03:01AM)
Error in FindAll Error HRESULT E_FAIL has been returned from a call to a COM component.(03:20AM)
Error in FindAll Error HRESULT E_FAIL has been returned from a call to a COM component.(03:25AM)"

Chicago David

unread,
Jun 11, 2023, 9:09:29 PM6/11/23
to Programmers
I thought I posted this and I apologize if it shows up twice.

I finally managed to read who is on mic as per the Paltalk instructions above. The key, I found, is to pay more attention to the Paltalk instructions and less attention to Microsoft documentation. I do have a couple of cases where Paltalk crashes though. 

I was reading the mic indicator and username with 

                    SendMessage(hwnd, LVM_GETITEMW, i, lviAddress)
                    SendMessage(hwnd, LVM_GETITEMTEXTA, i, lviAddress)

1. I found Paltalk would crash with the 2nd (GETITEMTEXTA) of the two messages. I can reproduce this crash by going into a room with myself and asking for the name of bogus user #2. In practice I believe it happens when I get a count of users and then on my iteration through the user list someone leaves the room. I'm currently programming around it by only calling GETITEMTEXTA only if the person is on mic (from the GETITEMW call).

2. I find if I exit the room and then come back so that I have to recreate handles to the room window and the (SysHeader32) control it also crashes Paltalk. This happens in a room with a lot of users (like over a hundred) and not in a room with few users (like under 10). So far I have gotten rid of the problem by putting in a sleep statement after noticing the room is back active and after searching for and finding the SysHeader32 control. I wonder even if SysHeader32 is there in the structure it needs a little time to populate the user list?

I can easily create both crashes for 1 & 2 in case Paltalk wants more information.
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

VN

unread,
Jun 13, 2023, 10:11:08 AM6/13/23
to Programmers
The fix will be delivered with the next 29.3 build.

Together with the fix, we added the ability to get the room member is asking for a microphone flag (Microphone queue flag). To get this flag, you need to send WM_USER + 1 event with the room member index in WPARAM.
Here is a Python code example:
memberIndex = 0
isAskingForMicrophone = win32gui.SendMessage(hwnd_send, win32con.WM_USER + 1,  memberIndex, 0)

Python code example is attached.

On Monday, June 12, 2023 at 4:52:16 PM UTC+7 RobotAI wrote:
To ChiCaGo David
Thank you for sharing your test program and the errors you encountered. It seems that you are using SendMessage to communicate with Paltalk and read the mic indicator and username. According to some web sources
, you may encounter some issues with SendMessage such as:

•  Pattern not found when using SendMessage with LVM_GETITEMW or LVM_GETITEMTEXTA, if the item index is out of range or the item does not exist. This may happen if the user list changes while you are iterating through it.

•  Error HRESULT E_FAIL when using SendMessage with LVM_GETITEMW or LVM_GETITEMTEXTA, if the window handle is invalid or the window is not responding. This may happen if the window is closed, minimized, or frozen.

•  Catastrophic failure when using SendMessage with LVM_GETITEMW or LVM_GETITEMTEXTA, if the memory allocation fails or the buffer size is insufficient. This may happen if the memory is low or the item text is too long.


Some possible solutions or workarounds are:

•  Use error handling and retry logic to catch and handle any exceptions or errors that may occur when using SendMessage functions. This may prevent your program from crashing or stopping unexpectedly.

•  Use synchronization and locking mechanisms to ensure that the user list does not change while you are iterating through it. This may avoid the pattern not found error caused by invalid item indexes.

•  Use PostMessage instead of SendMessage to send messages asynchronously and avoid blocking the UI thread. This may avoid the error HRESULT E_FAIL caused by unresponsive windows.

•  Use dynamic memory allocation and buffer resizing techniques to ensure that you have enough memory and buffer size to store the item data. This may avoid the catastrophic failure caused by memory allocation failure or buffer overflow.

I hope this helps you with your bot development.blush

Vào lúc 16:40:44 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, RobotAI đã viết:
To Chicago David
Thank you for sharing your test program and the errors you encountered. It seems that you are using UIAutomation to read the chat room and find all the children of the header element. According to some web sources https://stackoverflow.com/questions/40875385/uiautomation-findall-leaks-memory
https://stackoverflow.com/questions/32970247/automationelement-findall-performance-issue
https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findall
 you may encounter some issues with UIAutomation such as:
•  Memory leaks when using FindAll function, even if you release the array. This may cause your program to consume more memory over time and eventually crash.

•  Null pointer when using ElementFromHandle or FindFirst function, if the window or element is not found or created yet. This may happen if the window is closed, minimized, or not responsive.

•  Catastrophic failure when using FindFirst function, if the condition is not valid or the element is not accessible. This may happen if the element is hidden, disabled, or out of scope.

Some possible solutions or workarounds are:

•  Use PostMessage or SendMessage instead of UIAutomation to send input to the window. This may avoid the memory leaks and null pointers caused by UIAutomation functions.


•  Use FindWindowEx and EnumChildWindows instead of FindAll to find all the children of the header element by their class name. This may avoid the memory leaks and null pointers caused by UIAutomation functions.

•  Use FindWindowEx instead of ElementFromHandle to find the window handle by its class name and title. This may be more reliable and faster than UIAutomation.

•  Use error handling and retry logic to catch and handle any exceptions or errors that may occur when using UIAutomation functions. This may prevent your program from crashing or stopping unexpectedly.

•  Use performance updates for Windows 10 and .NET 4.6 that may fix some of the UIAutomation issues. According to an MS support representative
https://stackoverflow.com/questions/32970247/automationelement-findall-performance-issue  
they made some changes to improve the performance of UIAutomation in Windows 10.


Vào lúc 16:04:42 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, RobotAI đã viết:
To Chicago David
It seems that you are trying to use SendMessage to send Unicode characters to a window, you may need to use PostMessageW or SendMessageW instead of SendMessage, and set the CharSet property of the DllImport attribute to CharSet.Unicode. This may help you send the correct Unicode characters to the window. Alternatively, you may also try using WM_UNICHAR instead of WM_CHAR


Vào lúc 08:09:29 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, Chicago David đã viết:
paltalk_bot_example (1).py
Message has been deleted
Message has been deleted
Message has been deleted

Chicago David

unread,
Jun 14, 2023, 4:39:02 PM6/14/23
to Programmers
Thanks for that VN. I'm looking forward to using that new functionality. You said " The fix will be delivered with the next 29.3 build." Could you be more specific on what the fix is or what problem it is addressing?

I already put the read on mic functionality in my Paltalk timer bot in:

Also, I'm speaking only for myself, but this AI Robot doesn't seem very useful and is clogging up this otherwise fine channel.

Thanks to the Paltalk team for helping us.

-David

VN

unread,
Jun 14, 2023, 5:22:55 PM6/14/23
to Programmers
thanks for the feedback, i will limit robotAI from posting on the forum, but sometimes it can also help you to check your code, it can help you to see if the code is correct, or in Is this code using these commands compatible? Does it lead to congestion? Please allow me to close this topic, and you can comment in a new thread.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages