25

How do I download all chat messages or those from a particular room (over all time)? A script may be able to do it, but is there a more convenient way?

Is there something at https://data.stackexchange.com/ all I see are the QA sites.

16

In absence of any formal API, one can just obtain them by executing a POST request to http://chat.stackexchange.com/chats/<room_id>/events with form parameters:

  • mode: 'Messages' (there might be other modes, haven't checked.)
  • fkey: A valid user's fkey is required.
  • (optional) msgCount: integer, defaults to 100, capped to 500
  • (optional) before: message_id to to get messages prior to. If missing, it gets the most recent msgCount messages

Example Jupyter Notebook.

The returned value is a mapping with the following keys:

  • ms: Time it took for the query to run?
  • time: Time since Aug 4, 2014 in seconds???
  • sync: UNIX epoch time (mislabeled, or used to "sync" correct server-time to JS client?)
  • events: a list of up to msgCount messages (may be fewer if there aren't that many.) Each is a mapping with the following keys:
    • content: HTML-formatted message; may be missing if (removed).; Begins with "" if there's more content which is not contained in the event record (i.e. it was a long message; the full content, if desired, has to be individually fetched).
    • event_type: 1...only ever seen that.
    • message_edits: Integer, may be missing if not edited.
    • message_id: Integer; unique across all rooms on the chat server, but not between servers.
    • room_id: Integer
    • time_stamp: UNIX epoch, second-precision.
    • user_id: Integer, Chat.SE/Chat.MSE/Chat.SO user. Chat.SE ID is not related to a specific site or network ID; Chat.MSE and Chat.SO user IDs usually match the profile ID of the user on MSE and SO respectively, but that's not required. May be missing if the user_id no longer exists.
    • user_name: Name associated with user_id when the message was posted. If the user changes their username later, this does not update.
    • parent_id: Integer; Message ID to which this event is replying. May be an actual reply or just an @-ping. If it's the result of an @-ping, then this is the message ID of the most recent message by the pinged user. Usually missing if the message is not a actual or @-ping reply.
    • show_parent: Boolean; If true, then this is an actual reply and the replied-to arrow is shown. Usually missing if the message is not a direct reply.
    • moved: Boolean; If true, then this message has been moved from another room into its current room. Usually missing if the message has not been moved.
1
  • 1
    Tiny addendum: user_id ... may be missing if user no longer exists (At least that's my guess why, see eg message id 35969027, room 118)
    – bertieb
    Feb 6 '18 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .