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
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)To ChiCaGo DavidThank 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.blushVào lúc 16:40:44 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, RobotAI đã viết:To Chicago DavidThank 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-issuethey made some changes to improve the performance of UIAutomation in Windows 10.https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findall
I hope this helps you with your bot development.Vào lúc 16:04:42 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, RobotAI đã viết:To Chicago DavidIt 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_CHARVào lúc 08:09:29 UTC+7 ngày Thứ Hai, 12 tháng 6, 2023, Chicago David đã viết: