Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bing Chatbot support #225

Closed
robbely opened this issue Mar 2, 2023 · 19 comments
Closed

Bing Chatbot support #225

robbely opened this issue Mar 2, 2023 · 19 comments
Labels

Comments

@robbely
Copy link

robbely commented Mar 2, 2023

Skyperious is a github project that uses SkPy (you're probably already aware of it) to backup Skype conversations.

The recent Bing Chatbot, however is not being backed up (although it appears in my contacts like a regular contact), and the developer indicated the issues is likely with SkPy.

The chatbot conversations are clearly being stored online as I can access them from any device running Skype.

Does SkPy support accessing Bing Chatbot conversations or are there any plans for this support in the future?

@Terrance
Copy link
Owner

Terrance commented Mar 2, 2023

Assuming this bot is presented like other Skype bots, SkPy should be able to interact with it -- you'll need to be more specific on what's actually not working (see also the issue template).

@robbely
Copy link
Author

robbely commented Mar 4, 2023

It isn't easy to be more specific as I am accessing the library through a third-party app (Skyperious). The developer pointed out that he cannot fix this as the app relies on SkPy.

I have the "Skype" bot on my account and that is backed up fine, so there must be something different in the new chatbot. The Skyperious dev stated he couldn't get it to work either.

@Terrance
Copy link
Owner

Terrance commented Mar 4, 2023

Assuming this is the bot in question, I don't see any problems accessing its messages (my test account is not authorised to actually use the bot, though it does still seem to respond in a regular chat):

>>> sk.contacts.bot('cf0e6215-34fe-409b-9e4b-135d7f3aa13b')
SkypeBotUser(id='cf0e6215-34fe-409b-9e4b-135d7f3aa13b', name='Bing', avatar='https://bot-framework.azureedge.net/bot-icons-v1/OpenAiConnectProdBot_3IMAxA3sY6L41gsG8U7ca86E9uJANz54oFcZFvf9IC3tyEr3.png', developer='', trusted=True, locales=[], rating=0.0, description='Chat with Bing in Skype for quick answers and creative ideas to enhance any conversation. Bing can help you plan a trip, write a funny haiku, find answers from the web, and more. Just mention @Bing and ask!')

>>> sk.chats['28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b']
SkypeSingleChat(id='28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b', alerts=True, userId='cf0e6215-34fe-409b-9e4b-135d7f3aa13b')

>>> sk.chats['28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b'].getMsgs()
[SkypeTextMsg(id='1677763246411', type='RichText', time=datetime.datetime(2023, 3, 2, 13, 20, 46, 346000), clientId='2470777693493059435', userId='cf0e6215-34fe-409b-9e4b-135d7f3aa13b', chatId='28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b', content='I\'m sorry! (sad) I can\'t reply to you. If you have not joined the Bing waitlist yet, please <a href="https://go.skype.com/bingchatlearnmore">join here</a>.'),
 SkypeTextMsg(id='1677763244457', type='RichText', time=datetime.datetime(2023, 3, 2, 13, 20, 43, 943000), clientId='16797972230821603272', userId='fred.2', chatId='28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b', content='Hi')]

I'd suggest asking the Skyperious dev to chime in here if you're not using SkPy directly.

@robbely
Copy link
Author

robbely commented Mar 4, 2023

I've left a message with the Skyperious dev asking him to join in. Hopefully he can add some insight here.

@suurjaak
Copy link

suurjaak commented Mar 6, 2023

I can confirm that the Bing bot and its chat and messages are visible when addressing them directly, via skpy.Skype.contacts[..] and skpy.Skype.chats[..]. So that part works fine.

The problem is that its chat is not returned fromskpy.Skype.chats.recent(). So there is no way to discover the bot in an skpy session if relying on recent chats only.

At least that is the result in my setup, and apparently also in @robbely's setup. @Terrance, is the result different for you - does the chat get listed in skpy.Skype.chats.recent()?

@Terrance
Copy link
Owner

Terrance commented Mar 6, 2023

Looks like bots aren't being included at all, and we need to opt in to more chat types when requesting recent chats.

Can you give f09e922 a go? That should match what Skype for Web is requesting, and seems to be sufficient to include bots in the list of chats.

@suurjaak
Copy link

suurjaak commented Mar 7, 2023

The linked version works better, in that the Bing-bot chat is present in recent chats.

But there is some weirdness in whether the bot contact is returned as SkypeBotUser or SkypeContact.

When skpy.Skype.contacts.bot(..) is invoked first, then the bot contact is returned as SkypeBotUser from it, and also as such from its chat .user and .users.

But if the chat is queried first, then its .user is just of type SkypeContact, and skpy.Skype.contacts.bot(..) will also return it as SkypeContact not SkypeBotUser:

sk.contacts.bot("cf0e6215-34fe-409b-9e4b-135d7f3aa13b")
SkypeContact(id=u'cf0e6215-34fe-409b-9e4b-135d7f3aa13b', name=u'Bing', location=Location(), avatar=u'https://bot-framework.azureedge.net/bot-icons-v1/OpenAiConnectProdBot_3IMAxA3sY6L41gsG8U7ca86E9uJANz54oFcZFvf9IC3tyEr3.png', authorised=True, blocked=False, favourite=False)

The same applies for other bot users as well, like the concierge bot. Also when querying a bot from skpy.Skype.contacts[..] first - returned as SkypeContact from it and from any other source later.

@Terrance
Copy link
Owner

Terrance commented Mar 7, 2023

This is ultimately a limitation of Skype's APIs -- the contacts API will return bots you've started a chat with, with no indication from there that they're a bot, which means you'll get a SkypeContact instance for them instead.

If you need accurate representations, call SkypeContacts.bots() to cache all known bots as SkypeBotUser instances and SkypeContacts.sync() to cache contacts as SkypeContact instances first, then key lookups should produce the correct types.

@sjnaj
Copy link

sjnaj commented Mar 8, 2023

I got message from bingchat:"Sorry, I am not compatible with older versions of Skype. Please update to the latest Skype for us to talk. Thank you! (smileeyes)"

@sjnaj
Copy link

sjnaj commented Mar 9, 2023

It can be solved by add
headers={"ClientInfo":"os=Windows; osVer=10; proc=x86; lcid=en-US; deviceType=1; country=HK; clientName=skype4life; clientVer=1418/8.94.0.428//skype4life; timezone=Asia/Shanghai"}

I got message from bingchat:"Sorry, I am not compatible with older versions of Skype. Please update to the latest Skype for us to talk. Thank you! (smileeyes)"

@Terrance
Copy link
Owner

I've added a24999d to send that header -- not keen on coding a version in, but it seems to accept all nines which should hopefully keep it going for now. (I did try reading the version from the Skype for Web page, but it needs both a valid User-Agent else you hit the unsupported platform page, and working authentication that seems to be invalidated after you request the page...)

@suurjaak
Copy link

@Terrance Any plans to make a new release with these changes?

@Terrance
Copy link
Owner

I assume the above commit is sufficient to get things working for you?

@suurjaak
Copy link

Yes, f09e922 got bots included in recent chats.

@Terrance
Copy link
Owner

Released in 0.10.5.

@suurjaak
Copy link

suurjaak commented Apr 2, 2023

If you need accurate representations, call SkypeContacts.bots() to cache all known bots as SkypeBotUser instances and SkypeContacts.sync() to cache contacts as SkypeContact instances first, then key lookups should produce the correct types.

Unfortunately, this does not quite seem to be the case.

>>> bb = sk.contacts.bots()
>>> sk.contacts.sync()
>>> c = sk.chats["28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b"]
>>> c
SkypeSingleChat(id='28:cf0e6215-34fe-409b-9e4b-135d7f3aa13b', alerts=True, userId='cf0e6215-34fe-409b-9e4b-135d7f3aa13b')
>>> c.user
SkypeContact(id='cf0e6215-34fe-409b-9e4b-135d7f3aa13b', name=Name(first='Bing'), location=Location(), avatar='https://bot-framework.azureedge.net/bot-icons-v1/OpenAiConnectProdBot_3IMAxA3sY6L41gsG8U7ca86E9uJANz54oFcZFvf9IC3tyEr3.png', authorised=True, blocked=False, favourite=False)

May this be because the Bing bot is not actually among the ones returned from contacts.bots()?

>>> next((x for x in bb if "Bing" in x.name), "nope")
'nope'

@Terrance
Copy link
Owner

Terrance commented Apr 2, 2023

That's annoying -- it looks like Skype for Web fetches the bot info for that bot explicitly, I guess it's special-cased and known ahead of time (it does have its own category in the contact list), but it's still a bit weird that it's not included in the full list.

Potential workarounds:

In either case you can explicitly fetch a given user ID as a bot with SkypeContacts.bot(id).

@suurjaak
Copy link

suurjaak commented Apr 3, 2023

In either case you can explicitly fetch a given user ID as a bot with SkypeContacts.bot(id).

The caching interferes with this. Once the chat object has been returned, directly from chats[..] or viachats.recent(), a call to contacts.bot(..) will return the Bing bot as SkypeContact. Only when the Bing bot contact is first explicitly retrieved via contacts.bot(..), will it be SkypeBotUser in later returns.

However, contact.raw["person_id"] does have the bot prefix "28:", so the botness can be detected from that. Maybe skpy could check for this internally and ensure the correct contact class in what it returns?

@Terrance
Copy link
Owner

Terrance commented Apr 6, 2023

Only when the Bing bot contact is first explicitly retrieved via contacts.bot(..), will it be SkypeBotUser in later returns.

Indeed, the cache retains the type it first encountered -- you could interact with the cache directly via contacts.cache to evict it before, or just ensure you request your known bots before accessing them elsewhere.

contact.raw["person_id"] does have the bot prefix "28:"

So far I've left prefixes out of contacts, which is a bit of a historical pain point (during early guesswork it was assumed that fred.2 was a user identifier and 8:fred.2 was a chat identifier, which isn't the case) -- ideally the id would retain this information but that's tricky to fix without breaking compatiblity.

Implementation-wise, this probably wants a dispatching parser like SkypeMsg does to create an instance of the right subclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants