The Birth of "Skype Ai"
- Preface
Due to certain reasons, Microsoft's new Bing cannot be used in mainland China. Initially, there was a workaround by modifying the X-Forwarder-For in the header to bypass the regional restrictions. However, it was soon fixed. Hence, this article was created.
- Getting Started
Microsoft introduced NewBing into Skype, allowing users to use the NewBing feature in chats. The model used by New Bing is GPT4.0, which means we can use GPT4.0 for free in Skype. Unfortunately, private chats with NewBing in Skype still require the use of "magic" to activate.
Once the magic is cast, private chats with NewBing can be initiated. However, in group chats, there is no need to use magic to mention NewBing. It seems that we have found a breakthrough.
However, in mainland China, Skype is not as widely used as WeChat or QQ. If we need to use NewBing in Skype every time, do we have to open Skype, open the group chat, and mention NewBing every time? Therefore, I decided to use a Python script to call NewBing in Skype. Initially, I used Python web scraping to achieve this. However, after further research, I discovered the skpy library in Python. I have uploaded the entire code on GitHub, and I will only discuss some of the more challenging issues here. If you don't want to read further, you can directly go to my GitHub page.
Python Integration with Skype Group Chats
To access group conversations in Skype using skpy, the chats module is used, which requires the group ID as a parameter. The following code retrieves the group ID:
loggedInUser = Skype("[email protected]", "password")
getinfo = SkypeChats(loggedInUser)
print(getinfo.recent())
The output JSON includes the "Topic" parameter, which represents the name of the created group chat. The group ID can be located based on the group chat name, and the format of the group ID is usually: 19:[email protected]
Summoning BingChat
After integrating skpy into Python, it is possible to send messages to group chats in Python. However, simply mentioning NewBing in Python does not successfully activate it. By using BurpSuite to intercept the packets, it was discovered that a certain code snippet appears every time NewBing is mentioned:
<at id=\"28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b\">Bing</at>
Attempting to include this code snippet before the text to be sent successfully mentions NewBing. However, how can we receive messages in real-time after sending them? Because BingChat does not immediately respond after we send a message, the official documentation only provides a way to retrieve messages in the current conversation. I had to repeatedly search through the official documentation, and finally, my efforts paid off. I found the SkypeNewMessageEvent and SkypeEditMessageEvent methods (these two methods are at the bottom of the documentation, which I didn't notice due to my oversight). The SkypeNewMessageEvent method listens for and retrieves the latest messages, while the SkypeEditMessageEvent method listens for and retrieves the modified messages. Yes, Skype can modify messages in real-time. At that time, I didn't use the SkypeEditMessageEvent method because I was only testing with simple questions, and NewBing could provide answers in one sentence, so I didn't pay much attention to it. However, after multiple tests, I found that NewBing would often interrupt its response halfway, which puzzled me. I suddenly realized the existence of the SkypeEditMessageEvent, which can listen in real-time for message modifications and return the modified content.
Final Result
After adding some additional features, the final result is as follows:
Get the Code
You can find the code on GitHub. If you find it useful, please give it a star.