Topic Event webhook broken- false topic_created messages

I want to take some action when there is a new topic. So I have a webhook enabled for Topic Events. I check the headers to see whether it’s a topic_created event, and if so, I take action.

This worked for many months but now fails sometimes, possibly after upgrading last week. Now sometimes I get topic_created in the headers, however the topic is actually old and someone simply replied to the topic.

My code:

    event_type = request.headers['X-Discourse-Event-Type']
    event = request.headers['X-Discourse-Event']
    if event_type == 'topic' and event == 'topic_created':

Example payload from a request that had event == ‘topic_created’ in the headers. Note the alleged “new” topic actually was created in 2017 and has 306 replies.

	'bookmarked': False,
	'word_count': 272108,
	'visible': True,
	'like_count': 567,
	'highest_post_number': 758,
	'has_deleted': True,
	'tags_descriptions': {},
	'deleted_at': None,
	'archetype': 'regular',
	'id': 1357,
	'pinned_until': None,
	'archived': False,
	'user_id': 4,
	'title': 'Tax Time! Discussions of Taxes and Accountants',
	'last_posted_at': '2022-01-05T01:41:26.000Z',
	'tags': [],
	'created_by': {
		'username': 'redacted',
		'avatar_template': '/user_avatar/{size}/45_2.png',
		'id': 4,
		'name': 'redacted'
	'pinned': False,
	'queued_posts_count': 0,
	'closed': False,
	'unpinned': None,
	'participant_count': 162,
	'views': 19557,
	'pinned_at': None,
	'last_poster': {
		'username': 'redacted',
		'avatar_template': '/letter_avatar_proxy/v4/letter/j/45deac/{size}.png',
		'id': 142,
		'name': 'JohnJacobs'
	'pending_posts': [],
	'posts_count': 744,
	'slug': 'tax-time-discussions-of-taxes-and-accountants',
	'thumbnails': None,
	'created_at': '2017-01-21T00:25:01.000Z',
	'deleted_by': None,
	'featured_link': None,
	'reply_count': 306,
	'pinned_globally': False,
	'category_id': 16,
	'fancy_title': 'Tax Time! Discussions of Taxes and Accountants'

There is some evidence the false topic_created messages are triggered when someone replies by email.

I added a fix here

1 Like

This topic was automatically closed after 18 hours. New replies are no longer allowed.