Detect from topic payload if something was mailed or posted via web

I think I’m overlooking something, because I know the web gui shows a little mailbox icon, but how do I find out if a topic was mail-in or not? (I want to reply only for mail in)

1 Like

There should be a via_email property set to true on the posts mailed in.

1 Like

hrmm that’s not what I get via a webhook post data:

{
  "topic": {
    "id": 13771,
    "title": "****",
    "fancy_title": "***",
    "posts_count": 1,
    "created_at": "2017-07-24T19:04:15.000Z",
    "views": 0,
    "reply_count": 0,
    "participant_count": 1,
    "like_count": 0,
    "last_posted_at": "2017-07-24T19:04:15.000Z",
    "visible": true,
    "closed": false,
    "archived": false,
    "has_summary": false,
    "archetype": "private_message",
    "slug": "****",
    "category_id": null,
    "word_count": 400,
    "deleted_at": null,
    "pending_posts_count": 0,
    "user_id": 377,
    "pm_with_non_human_user": false,
    "draft": null,
    "draft_key": "topic_13771",
    "draft_sequence": 0,
    "unpinned": null,
    "pinned_globally": false,
    "pinned": false,
    "pinned_at": null,
    "pinned_until": null,
    "details": {
      "created_by": {
        "id": 377,
        "username": "**",
        "avatar_template": "**"
      },
      "last_poster": {
        "id": 377,
        "username": "**",
        "avatar_template": "**"
      },
      "allowed_groups": [
        {
          "id": 50,
          "automatic": false,
          "name": "support",
          "user_count": 12,
          "alias_level": 99,
          "visibility_level": 1,
          "automatic_membership_email_domains": "",
          "automatic_membership_retroactive": false,
          "primary_group": false,
          "title": "Support",
          "grant_trust_level": 4,
          "incoming_email": "**",
          "has_messages": true,
          "flair_url": "fa-cog",
          "flair_bg_color": null,
          "flair_color": "800000",
          "bio_raw": null,
          "bio_cooked": null,
          "public": false,
          "allow_membership_requests": false,
          "full_name": null,
          "default_notification_level": 3
        }
      ],
      "allowed_users": [
        {
          "id": 377,
          "username": "**",
          "avatar_template": ""
        }
      ],
      "participants": [
        {
          "id": 377,
          "username": "**",
          "avatar_template": "",
          "post_count": 1,
          "primary_group_name": null,
          "primary_group_flair_url": null,
          "primary_group_flair_color": null,
          "primary_group_flair_bg_color": null
        }
      ],
      "notification_level": 1,
      "can_move_posts": true,
      "can_edit": true,
      "can_delete": true,
      "can_remove_allowed_users": true,
      "can_invite_to": true,
      "can_create_post": true,
      "can_reply_as_new_topic": true,
      "can_flag_topic": true
    },
    "highest_post_number": 1,
    "deleted_by": null,
    "has_deleted": false,
    "actions_summary": [
      {
        "id": 4,
        "count": 0,
        "hidden": false,
        "can_act": true
      },
      {
        "id": 7,
        "count": 0,
        "hidden": false,
        "can_act": true
      },
      {
        "id": 8,
        "count": 0,
        "hidden": false,
        "can_act": true
      }
    ],
    "chunk_size": 20,
    "bookmarked": null,
    "message_archived": false,
    "tags": [],
    "featured_link": null,
    "topic_timer": null,
    "message_bus_last_id": 13,
    "can_vote": false,
    "vote_count": null,
    "user_voted": false
  }
}

(stripped the non relevant/private stuff)

1 Like

Maybe the data is missing from the serializer we’re using when sending a webhook?

Ah sorry; I didn’t realise that would be different from the regular one (they look a lot alike)

:thinking: Looks like the WebHookPostSerializer is inheriting from the PostSerializer so the via_email property should be there

https://github.com/discourse/discourse/blob/master/app/serializers/web_hook_post_serializer.rb

2 Likes

it looks like the topic endpoint only gets the topic itself, not the posts (the post has via_email)

2 Likes

Consider this solved. I’ll use the API to get the posts to get this imfo

3 Likes