Microsoft Tech Community Live:  Microsoft Teams Edition
November 09, 2021, 08:00 AM - 12:00 PM (PST)

Deleting messages on iOS

%3CLINGO-SUB%20id%3D%22lingo-sub-2675921%22%20slang%3D%22en-US%22%3EDeleting%20messages%20on%20iOS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2675921%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20an%20MS%20Teams%20chatbot%3B%20to%20operate%20it%2C%20we%20do%20not%20use%20the%20relevant%20language%20SDK%20(Python)%20because%20our%20app%20also%20operates%20on%20other%20platforms%2C%20like%20Slack.%20The%20bot%20is%20only%20for%201-on-1%20chats.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20problem%20is%20when%20we%20send%20a%20multiple-choice%20question%20to%20a%20user%20running%20the%20iOS%20Teams%20app.%20The%20intended%20behavior%2C%20which%20is%20what%20we%20get%20in%20all%20other%20cases%20(desktop%20app%2C%20Android%2C%20browser%2C%20as%20well%20as%20Slack%20and%20other%20platforms)%20is%20that%2C%20after%20the%20user%20chooses%20an%20answer%2C%20the%20buttons%20all%20disappear%20and%20leave%20no%20trace.%20This%20is%20to%20keep%20them%20focused%20on%20the%20current%20question%20and%20avoid%20getting%20useless%20extra%20answers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20iOS%2C%20the%20buttons%20do%20get%20deleted%2C%20but%20they%20leave%20a%20trace%20-%20a%20gray%20box%20stating%20that%20a%20message%20was%20deleted.%20We%20would%20like%20to%20get%20rid%20of%20that.%20How%20do%20we%20achieve%20this%3F%20We%20currently%20use%20Hero%20cards%2C%20but%20have%20the%20capability%20to%20use%20Adaptive%20cards%20as%20well.%20I%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20the%20code%20that%20sends%20the%20delete%20request%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3E%23%20teams.py%0A%0A%40shared_task%0Adef%20delete_inline_keyboards_teams(chat%2C%20new_message_id)%3A%0A%20%20%20%20with%20chat.bot.platform.lock(chat.id%2C%20'delete_inline_keyboards')%3A%0A%20%20%20%20%20%20%20%20chat_messages_with_buttons%20%3D%20redis_connection.smembers(f'%7Bchat.id%7D-keyboards')%0A%20%20%20%20%20%20%20%20for%20line%20in%20chat_messages_with_buttons%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20with%20Capture()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20message_id%2C%20activity_id%20%3D%20line.decode().split('%3A')%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20int(message_id)%20%26lt%3B%20new_message_id%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20response%20%3D%20chat.bot.platform.delete_activity(chat.service_url%2C%20chat.conversation.id%2C%20activity_id)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20response.status_code%20%3D%3D%20status.HTTP_200_OK%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20PlatformException(chat.bot.platform.code%2C%20response)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20redis_connection.srem(f'%7Bchat.id%7D-keyboards'%2C%20line)%0A%0Aclass%20Teams(Platform)%3A%0A%20%20%20%20def%20delete_activity(self%2C%20base_uri%2C%20conversation_id%2C%20activity_id)%3A%0A%20%20%20%20%20%20%20%20headers%20%3D%20%7B'content-type'%3A%20'application%2Fjson%3B%20charset%3Dutf-8'%2C%20'Authorization'%3A%20f'Bearer%20%7Bself.access_token%7D'%7D%0A%20%20%20%20%20%20%20%20url%20%3D%20f'%2Fv3%2Fconversations%2F%7Bconversation_id%7D%2Factivities%2F%7Bactivity_id%7D'%0A%20%20%20%20%20%20%20%20return%20requests.delete(f'%7Bbase_uri%7D%2F%7Burl%7D'%2C%20headers%3Dheaders)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2675921%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2679926%22%20slang%3D%22en-US%22%3ERe%3A%20Deleting%20messages%20on%20iOS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2679926%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1135344%22%20target%3D%22_blank%22%3E%40brunoparga%3C%2FA%3E%20-%20Are%20you%20deleting%20question%20card%20itself%20or%20only%20removing%20the%20buttons%20from%20the%20card%3F%3CBR%20%2F%3ECould%20you%20please%20also%20try%20it%20with%20Adaptive%20Card.%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello,

 

I have an MS Teams chatbot; to operate it, we do not use the relevant language SDK (Python) because our app also operates on other platforms, like Slack. The bot is only for 1-on-1 chats.

 

My problem is when we send a multiple-choice question to a user running the iOS Teams app. The intended behavior, which is what we get in all other cases (desktop app, Android, browser, as well as Slack and other platforms) is that, after the user chooses an answer, the buttons all disappear and leave no trace. This is to keep them focused on the current question and avoid getting useless extra answers.

 

On iOS, the buttons do get deleted, but they leave a trace - a gray box stating that a message was deleted. We would like to get rid of that. How do we achieve this? We currently use Hero cards, but have the capability to use Adaptive cards as well. I 

 

Here's the code that sends the delete request:

 

# teams.py

@shared_task
def delete_inline_keyboards_teams(chat, new_message_id):
    with chat.bot.platform.lock(chat.id, 'delete_inline_keyboards'):
        chat_messages_with_buttons = redis_connection.smembers(f'{chat.id}-keyboards')
        for line in chat_messages_with_buttons:
            with Capture():
                message_id, activity_id = line.decode().split(':')
                if int(message_id) < new_message_id:
                    response = chat.bot.platform.delete_activity(chat.service_url, chat.conversation.id, activity_id)
                    if not response.status_code == status.HTTP_200_OK:
                        raise PlatformException(chat.bot.platform.code, response)
                    redis_connection.srem(f'{chat.id}-keyboards', line)

class Teams(Platform):
    def delete_activity(self, base_uri, conversation_id, activity_id):
        headers = {'content-type': 'application/json; charset=utf-8', 'Authorization': f'Bearer {self.access_token}'}
        url = f'/v3/conversations/{conversation_id}/activities/{activity_id}'
        return requests.delete(f'{base_uri}/{url}', headers=headers)

 

 

1 Reply
@brunoparga - Are you deleting question card itself or only removing the buttons from the card?
Could you please also try it with Adaptive Card.