Skip to content

Instantly share code, notes, and snippets.

@kiki67100
Last active November 5, 2024 14:04
Show Gist options
  • Save kiki67100/6c68436766ea3a037508970999b7e89e to your computer and use it in GitHub Desktop.
Save kiki67100/6c68436766ea3a037508970999b7e89e to your computer and use it in GitHub Desktop.
Delete batch messages Microsoft Teams
/*
This version is probably out of date, look at the dsci4-hacks ( Thanks to him x) ) instead:
*** not tested ***
https://github.com/dsci4-hacks/Delete-Teams-Messages/blob/main/delete_my_teams_messages.js
Thank you for all your contributions in comments
**** Original ****
By kiki67100 https://gist.github.com/kiki67100
Tested on Google Chrome
Open Microsoft teams web version, select a conversation
Open Developper tools and copy / paste (Change YOUR_NAME by your)
Work on March 2020 maybe no work on the future...
*/
window.id = [];
YOUR_NAME = "YOUR_NAME";
window.idx=0;
setInterval(function() {
jQuery('#page-content-wrapper').find('div[id^=m]').each(function() {
$('virtual-repeat').scrollTop(0);
setTimeout(function(_this) {
//console.log('timeout...');
//console.log('_this = ',_this);
txt = $(_this).text();
if (txt.indexOf(YOUR_NAME) != -1) {
console.log('not inside');
$(_this).css({
'outline': '1px solid red'
});
_id = $(_this).attr('id');
//console.log('_this id =' + _id)
if (window.id.indexOf(_id) == -1) {
window.id.push(_id.substr(1));
//console.log('add');
} else {
//console.log('!!');
}
}else{
//console.log('already inside');
}
}, 1000, this);
});
}, 2000);
/*
- Extract messages id
On Google Chrome developper tools :
copy(id.join("\n"))
Delete a message, copy the ajax request and export as CURL (bash) (on network tools maybe end by "softDelete")
On notepad ++ on replace regex mode
REPLACE (.*)
Your CURL shell command find the id curl 'https://emea.[...]/121545326566?behavior=softDelete by $1 like this 'https://emea.[...]/$1?behavior=softDelete
lauch on linux terminal all lines
*/
@Battle9
Copy link

Battle9 commented May 19, 2021

I tested it, It can functional BUT in a short time I receive DELETE https://amer.[.......]messages/1620283331183?behavior=softDelete 429 error. So it is too fast. I tried several method for slow down the script but I couldn't.

@matrad4307
Copy link

I tested it, It can functional BUT in a short time I receive DELETE https://amer.[.......]messages/1620283331183?behavior=softDelete 429 error. So it is too fast. I tried several method for slow down the script but I couldn't.

Hi,did you solve the problem of sending reqests too fast?

@Battle9
Copy link

Battle9 commented Aug 27, 2021

I disabled the automatic scroll up and I use my scroll button of the mouse to move up the window manually. In this case I can manipulate the speed. anyway: I use a VAR with the message IDs and I never try to remove 1 ID twice -> lower number of error..

@bnff
Copy link

bnff commented Sep 28, 2021

Hello,

Obviously it correctly selects my message in a red frame!
what should I do to remove them now?
Thank you

Edit ; Ok i have List id of all msg and now ?

@Endeer
Copy link

Endeer commented Oct 14, 2021

Hello. This code should work today (October 2021) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window while it is running. The code simulates mouse movement and clicks, you would interfere with it.

(function() {
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var repeat = setInterval(function() {
		if(loading) {
			if($("div.pending").size() == 0) {
				loading = false;
				jQuery('#page-content-wrapper').find('div[id^=m].self').each(function() {
					var id = $(this).attr('id').substr(1);
					if(isNaN(id)) return;
					if($(this).attr("data-tid").indexOf('tombstone') != -1) return;
		
					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			$(item).css({'outline': '5px solid #cc0'});

			// cleanup of possible leftover mess
			if($("message-actions").size() > 0) {
				$("[id=messageBody]").trigger("mouseout");
			}

			console.log("Delete ID " + $(item).attr("id"));
			$(item).find("#messageBody").trigger("mouseover");
			setTimeout(function() { $("message-actions button.message-actions-more").trigger("click"); }, 500);
			setTimeout(function() { $("div#messageActionDropdown button[track-summary=Delete]").trigger("click"); }, 1000);

			last_processed = (new Date()).getTime();
		}
		else {
			$('virtual-repeat').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 2000);
})();

@FrBillyD
Copy link

Thanks a lot ! 🙏 The last script is working fine ! 👍

@Battle9
Copy link

Battle9 commented Mar 28, 2022

Hello. This code should work today (October 2021) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window while it is running. The code simulates mouse movement and clicks, you would interfere with it.

(function() {
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var repeat = setInterval(function() {
		if(loading) {
			if($("div.pending").size() == 0) {
				loading = false;
				jQuery('#page-content-wrapper').find('div[id^=m].self').each(function() {
					var id = $(this).attr('id').substr(1);
					if(isNaN(id)) return;
					if($(this).attr("data-tid").indexOf('tombstone') != -1) return;
		
					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			$(item).css({'outline': '5px solid #cc0'});

			// cleanup of possible leftover mess
			if($("message-actions").size() > 0) {
				$("[id=messageBody]").trigger("mouseout");
			}

			console.log("Delete ID " + $(item).attr("id"));
			$(item).find("#messageBody").trigger("mouseover");
			setTimeout(function() { $("message-actions button.message-actions-more").trigger("click"); }, 500);
			setTimeout(function() { $("div#messageActionDropdown button[track-summary=Delete]").trigger("click"); }, 1000);

			last_processed = (new Date()).getTime();
		}
		else {
			$('virtual-repeat').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 2000);
})();

Something has changed and the code doesn't work. Could you check it, please? :)

@sadagst
Copy link

sadagst commented Mar 31, 2022

Sorry, can someone make a video of the whole procedure? I can't get it to work :(

@Battle9
Copy link

Battle9 commented Apr 12, 2022

Hello. This code should work today (October 2021) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window while it is running. The code simulates mouse movement and clicks, you would interfere with it.

Endeer, I really appreciate your work. But now I see: something is change in teams and your code is not working anymore :( I'm not enough to fix the code and find what is the problem.

kiki67100 your code is also not working and I can't fix it.

Could you check it, please? Thank you

@Endeer
Copy link

Endeer commented Apr 12, 2022

Hello. I have spared some time for poor souls using Microsoft Teams.

This code should work today (April 2022) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window with mouse cursor while it is running. The code simulates mouse movement and clicks, you would interfere with it.

(function() {
	var JQ = jQuery("iframe").contents();
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var my_name = null;
	var mouse = function(which, element) {
		var evt = element.ownerDocument.createEvent('MouseEvents');
		
		evt.initMouseEvent(which, true, true,
			element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
			false, false, false, 1, null);
		
		element.dispatchEvent(evt);
	}

	var repeat = setInterval(function() {
		if(loading) {
			if(JQ.find("div.pending").size() == 0) {
				loading = false;
				JQ.find('div[data-mid]').each(function() {
					var id = $(this).attr('data-mid');
					if(isNaN(id)) return;

					if($(this).find("[data-tid=message-undo-delete-btn]").size() > 0) return;

					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			if(my_name && my_name != $(item).find("[data-tid=message-author-name]").text()) return;

			$(item).css({'outline': '5px solid #cc0'});
			console.log("Delete ID " + $(item).attr("data-mid"));
			mouse('contextmenu', $(item).find(".ui-chat__message__content>div")[0]);
			setTimeout(function() {
				var delete_button = JQ.find("[data-tid=message-actions-delete]")[0];
				if(delete_button) {
					my_name = $(item).find("[data-tid=message-author-name]").text();
					console.log(["My name is: ", my_name]);
					mouse('click', delete_button);
				}
			}, 100);

			last_processed = (new Date()).getTime();
		}
		else {
			JQ.find('[data-tid=message-pane-list-viewport]').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 1000);
})();

@Battle9
Copy link

Battle9 commented Apr 13, 2022

Hello. I have spared some time for poor souls using Microsoft Teams.

ahahha "poor souls" :)

Thank you, It works! Awesome

@zoom-maestro
Copy link

It's super duper zippy too. Much faster than before. Thanks!

@sadagst
Copy link

sadagst commented May 3, 2022

Hello. I have spared some time for poor souls using Microsoft Teams.

This code should work today (April 2022) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window with mouse cursor while it is running. The code simulates mouse movement and clicks, you would interfere with it.

(function() {
	var JQ = jQuery("iframe").contents();
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var my_name = null;
	var mouse = function(which, element) {
		var evt = element.ownerDocument.createEvent('MouseEvents');
		
		evt.initMouseEvent(which, true, true,
			element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
			false, false, false, 1, null);
		
		element.dispatchEvent(evt);
	}

	var repeat = setInterval(function() {
		if(loading) {
			if(JQ.find("div.pending").size() == 0) {
				loading = false;
				JQ.find('div[data-mid]').each(function() {
					var id = $(this).attr('data-mid');
					if(isNaN(id)) return;

					if($(this).find("[data-tid=message-undo-delete-btn]").size() > 0) return;

					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			if(my_name && my_name != $(item).find("[data-tid=message-author-name]").text()) return;

			$(item).css({'outline': '5px solid #cc0'});
			console.log("Delete ID " + $(item).attr("data-mid"));
			mouse('contextmenu', $(item).find(".ui-chat__message__content>div")[0]);
			setTimeout(function() {
				var delete_button = JQ.find("[data-tid=message-actions-delete]")[0];
				if(delete_button) {
					my_name = $(item).find("[data-tid=message-author-name]").text();
					console.log(["My name is: ", my_name]);
					mouse('click', delete_button);
				}
			}, 100);

			last_processed = (new Date()).getTime();
		}
		else {
			JQ.find('[data-tid=message-pane-list-viewport]').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 1000);
})();

@Endeer you are top player! :)

@breakthefunk
Copy link

Hello. I have spared some time for poor souls using Microsoft Teams.

This code should work today (April 2022) and automatically delete messages. Tested on Firefox. Just open Teams, select conversation, and run this code from the Console, it should delete all your messages in the currently selected conversation.

It should only scroll up, so if you want to only delete messages older than X, just scroll to date X and run the script then. However this is not 100%, it may delete more. Always expect all your messages might be deleted.

IMPORTANT: Do not enter the browser window with mouse cursor while it is running. The code simulates mouse movement and clicks, you would interfere with it.

(function() {
	var JQ = jQuery("iframe").contents();
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var my_name = null;
	var mouse = function(which, element) {
		var evt = element.ownerDocument.createEvent('MouseEvents');
		
		evt.initMouseEvent(which, true, true,
			element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
			false, false, false, 1, null);
		
		element.dispatchEvent(evt);
	}

	var repeat = setInterval(function() {
		if(loading) {
			if(JQ.find("div.pending").size() == 0) {
				loading = false;
				JQ.find('div[data-mid]').each(function() {
					var id = $(this).attr('data-mid');
					if(isNaN(id)) return;

					if($(this).find("[data-tid=message-undo-delete-btn]").size() > 0) return;

					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			if(my_name && my_name != $(item).find("[data-tid=message-author-name]").text()) return;

			$(item).css({'outline': '5px solid #cc0'});
			console.log("Delete ID " + $(item).attr("data-mid"));
			mouse('contextmenu', $(item).find(".ui-chat__message__content>div")[0]);
			setTimeout(function() {
				var delete_button = JQ.find("[data-tid=message-actions-delete]")[0];
				if(delete_button) {
					my_name = $(item).find("[data-tid=message-author-name]").text();
					console.log(["My name is: ", my_name]);
					mouse('click', delete_button);
				}
			}, 100);

			last_processed = (new Date()).getTime();
		}
		else {
			JQ.find('[data-tid=message-pane-list-viewport]').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 1000);
})();

Hi, any chance you could look at the code again? It initially deletes messages but it does not scroll up and goes awol after the first batch. Tested on Chrome and Firefox. Thanks for any tips.

@maesutre
Copy link

Hi, thank you for the script. I'm having the same issue as breakthefunk here. It starts deleting messages and stops after a few messages. Doesn't scroll up either. Could you please update it? Thank you so much.

@NaPeK
Copy link

NaPeK commented Sep 25, 2022

@sadagst BRILLIANT !!! Unfortunately you have to scroll with the mouse so that the script does not hang

But still best solution I found on internets

@simwinaga
Copy link

@Endeer could you please update your script? it doesn't work anymore. it marks some messages, but no right click and no delete anymore.

@Zegorax
Copy link

Zegorax commented Oct 27, 2022

Hello everyone,

I have adapted the script and it is working now (27-OCT-2022). They changed .ui-chat__message__content to .ui-chat__messagecontent.

(function() {
	var JQ = jQuery("iframe").contents();
	var queue = [];
	var last_processed = (new Date()).getTime();
	var loading = true;
	var my_name = null;
	var mouse = function(which, element) {
		var evt = element.ownerDocument.createEvent('MouseEvents');
		
		evt.initMouseEvent(which, true, true,
			element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
			false, false, false, 1, null);
		
		element.dispatchEvent(evt);
	}

	var repeat = setInterval(function() {
		if(loading) {
			if(JQ.find("div.pending").size() == 0) {
				loading = false;
				JQ.find('div[data-mid]').each(function() {
					var id = $(this).attr('data-mid');
					if(isNaN(id)) return;

					if($(this).find("[data-tid=message-undo-delete-btn]").size() > 0) return;

					queue.push(this);
					$(this).css({'outline': '5px solid #000'});
				});
			}
			else return;
		}

		if(queue.length > 0) {
			var item = queue.shift();
			if(my_name && my_name != $(item).find("[data-tid=message-author-name]").text()) return;

			$(item).css({'outline': '5px solid #cc0'});
			console.log("Delete ID " + $(item).attr("data-mid"));
			mouse('contextmenu', $(item).find(".ui-chat__messagecontent>div")[0]);
			setTimeout(function() {
				var delete_button = JQ.find("[data-tid=message-actions-delete]")[0];
				if(delete_button) {
					my_name = $(item).find("[data-tid=message-author-name]").text();
					console.log(["My name is: ", my_name]);
					mouse('click', delete_button);
				}
			}, 100);

			last_processed = (new Date()).getTime();
		}
		else {
			JQ.find('[data-tid=message-pane-list-viewport]').scrollTop(0);
			loading = true;
		}
		
		if(last_processed < (new Date()).getTime() - 15000) {
			// if no new messages are coming up for 15s, consider it finished
			clearInterval(repeat);
			console.log("Finished, nothing new has come up for 15 seconds.");
		}
	
	}, 1000);
})();

@simwinaga
Copy link

@Zegorax it works. thank you very much!

Copy link

ghost commented Nov 9, 2022

Hello @Zegorax
First, congrates to everyone. This code is awesome to stop Microsoft abuse. I know people that lost hours by month to delete message by message on teams.
i think update (27-OCT-2022) is not working. Several times does not scroll, It freezes, its gives errors of HTTP 429 Too Many Requests, it has irregular behavior. It deletes messages that appear latter. Tested on EDGE and Chrome

@alexpeter-pen
Copy link

Improvement in two directions: it scrolls up as it meets the elements, and it skips over those that are not to be deleted faster. It still may stop here and there especially if some of the messages are very big, but either zoom in or nudge with the mouse. Good thing is that if you switch from one chat to another it will seemingly start deleting the messages in other chat too. I had probably thousand of messages and it worked quite well and finished that many messages in less than 20 minutes. Sure you will get too many calls occasionally but I would just refresh the screen, start the script again and it would delete if any message was not deleted yet. Taking into account what this script does and how it does it, I do not think that you can expect deleting more than 1 message per second. And this one with a hiccup here and there is doing just that.

 (function() {
     var JQ = jQuery("iframe").contents();
     var queue = [];
     var last_processed = (new Date()).getTime();
     var loading = true;
     var my_name = null;

     var mouse = function(which, element) {
         var evt = element.ownerDocument.createEvent('MouseEvents');

         evt.initMouseEvent(which, true, true,
             element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false,
             false, false, false, 1, null);

         element.dispatchEvent(evt);
     }

     var repeat = setInterval(function() {

         if (loading) {

             if (JQ.find("div.pending").size() == 0) {
                 loading = false;
                 $(JQ.find('div[data-mid]').get().reverse()).each(function() {
                     var id = $(this).attr('data-mid');
                     if (isNaN(id)) return;

                     if ($(this).find("[data-tid=message-undo-delete-btn]").size() > 0) return;

                     queue.push(this);
                     $(this).css({
                         'outline': '5px solid #blue'
                     });
                 });
             } else return;
         }


         while (true) {
             if (queue.length > 0) {
                 var item = queue.shift();
                 if (my_name && my_name != $(item).find("[data-tid=message-author-name]").text()) {
                     $(item).css({
                         'outline': '5px solid red'
                     });
                 } else {
                     $(item).css({
                         'outline': '5px solid blue'
                     });
                     mouse('contextmenu', $(item).find(".ui-chat__messagecontent>div")[0]);

                     var delete_button = JQ.find("[data-tid=message-actions-delete]")[0];
                     if (delete_button) {
                         console.log("Delete ID " + $(item).attr("data-mid"));
                         $(item).css({
                             'outline': '5px solid green'
                         });
                         my_name = $(item).find("[data-tid=message-author-name]").text();
                         console.log(["My name is: ", my_name]);
                         mouse('click', delete_button);
                         last_processed = (new Date()).getTime();
                         break;
                     } else {
                         $(item).css({
                             'outline': '5px solid red'
                         });
                     }
                 }

                 setTimeout(function() {
                     $(item)[0].scrollIntoView(false);
                 }, 100);

             } else
                 break;

         }

         if (queue.length <= 0) {
             loading = true;

         }

         if (last_processed < (new Date()).getTime() - 15000) {
             // if no new messages are coming up for 15s, consider it finished
             clearInterval(repeat);
             console.log("Finished, nothing new has come up for 15 seconds.");
         }
     }, 1000);
 })();

Copy link

ghost commented Nov 25, 2022

@alexpeter-pen lots of thanks but is to fast on delete. 429 (Too Many Requests) errors on many messages. its seems that deletes but does not delete. they appear again on refresh. To protect Microsoft Teams and its users, the bot APIs provide a rate limit for incoming request https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/rate-limit
can you please resolve it? i've tried to put a code to slow script but no lucky, i think ive only delayed the start.

@alexpeter-pen
Copy link

@geoginho I think I explained it in my comment about the rate limit, what is actually happening. I had to go twice about it over the same chat. But it is still faster than the initial solution overall and more reliable. If it bothers anyone the only way to try fixing the rate limit is to increase 1000 to something higher, but even then there is no guarantee that it will not happen.

Copy link

ghost commented Nov 25, 2022

@alexpeter-pen cool! its was easy than the solutions i was looking. its is running on 5 minutes and without messages of rate limit. i've changed 1000 to 2000. I have 3 years of messages and rate limit bothers a lot because i have to restart a 20 or 30 times from the beginning to try do delete messages that cannot be deleted before. Now on 2000 it is running and deleting all. Many thanks!!! Ops. To many requests now. I think that has a limit on total of deletes. Refresh and start again and here he goes more 5 minutes without any errors.

@ndstate
Copy link

ndstate commented Mar 31, 2023

This is great, thanks. Does anyone have something similar for Skype?

@PiotrSejbukPL
Copy link

Script stopped working and shows errors

Uncaught TypeError: Cannot read properties of undefined (reading 'ownerDocument')
and TypeError: Cannot read properties of undefined (reading 'ownerDocument')

@dsci4-hacks
Copy link

dsci4-hacks commented Jul 17, 2023

Here is an updated working version of the script as of 17/07/2023:

https://github.com/dsci4-hacks/Delete-Teams-Messages/blob/main/delete_my_teams_messages.js

@geog2
Copy link

geog2 commented Jun 12, 2024

Hello everyone.
Script does not work with New Teams. The option to go back to Old Teams is not available anymore. Can the experts revise the code to work with New Teams?
Regards!

@bnff
Copy link

bnff commented Sep 30, 2024

Hello

I'm quitting in 2 months, guys, I need you :D

@bakaschwarz
Copy link

Yeah, i am also kinda desparate 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment