API
General information
This service exposes an API at the base URL https://recent-messages.robotty.de/api/v2/.
CORS is enabled for the entire API, for all origins. You are free to use this API from client-side web apps and applications.
If you are developing a user-facing application and planning to integrate
with this service, you must follow these basic guidelines:
If feasible, you should always prefer to get user's consent via a opt-in before
the integration is enabled for them. On the Opt-in dialog, include a short paragraph
about what the service does and what feature(s) it provides in your application,
and give a link to this website ( https://recent-messages.robotty.de/). Here is a good example that you can follow.
If it's not realistic/possible to use an opt-in system, you must at the very least have an opt-out settings section with the same sort of information that would otherwise be shown on the opt-in dialog (info text, opt-out toggle, link to website).
If in doubt, please contact me about your integration and ask for help/confirmation before going forward. Contact details can be found on the home page.
Endpoints
Get recent messages
GET https://recent-messages.robotty.de/api/v2/recent-messages/:channel_login
Path parameters:
channel_login: Twitch login name of the channel messages should be returned for
Query parameters:
?hide_moderation_messages=true/false: OmitsCLEARCHATandCLEARMSGmessages from the response. Optional, defaults tofalse.?hide_moderated_messages=true/false: Omits all messages from the response that have been deleted by aCLEARCHATorCLEARMSGmessage. Optional, defaults tofalse.?clearchat_to_notice=true/false: ConvertsCLEARCHATmessages intoNOTICEmessages with a user-presentable message.Examples:
@historical=1;msg-id=rm-clearchat;rm-received-ts=1596058443362 :tmi.twitch.tv NOTICE #randers :Chat has been cleared by a moderator.
@historical=1;msg-id=rm-timeout;rm-received-ts=1596058460738 :tmi.twitch.tv NOTICE #randers :ed0mer has been timed out for 10m 30s.
@historical=1;msg-id=rm-permaban;rm-received-ts=1596058421611 :tmi.twitch.tv NOTICE #pajlada :a_bad_user has been permanently banned.The
msg-idwill be set torm-clearchat,rm-timeoutorrm-permaban, corresponding with the type of message.This option was originally introduced as a "quick fix" to get recent-messages integration to work with Chatterino. This option is now only retained to keep compatibility with old versions of Chatterino. You should try and avoid using this option if possible.
Optional, defaults to
false.?limit=n: Limit the number of messages returned. If more thannmessages are available for the requested channel, the response is limited to thennewest messages. Optional, defaults to no limit (up to 800 messages). Can be combined with?before=and?after=, the three requirements combine using a logical AND.
It is strongly recommended that you set this to some reasonable number based on your application, e.g. 50 or 100 tends to be more than enough for general-purpose chat clients.?before=n: Only return messages that were received before (<) this timestamp (in milliseconds since the unix epoch, this refers to therm-received-rstimestamp). Optional, can be combined with?limit=and?after=, the three requirements combine using a logical AND.?after=n: Only return messages that were received after (>) this timestamp (in milliseconds since the unix epoch, this refers to therm-received-rstimestamp). Optional, can be combined with?limit=and?before=, the three requirements combine using a logical AND.
Response format:
{
"messages": [
"@badge-info=;badges=glhf-pledge/1;color=;display-name=purplereddish;emotes=;flags=;historical=1;id=dbb10be8-581e-4f22-ba12-2001e088529d;mod=0;rm-received-ts=1596061057185;room-id=71092938;subscriber=0;tmi-sent-ts=1596061056790;turbo=0;user-id=260969632;user-type= :purplereddish!purplereddish@purplereddish.tmi.twitch.tv PRIVMSG #xqcow LULW",
"@badge-info=subscriber/9;badges=subscriber/9;client-nonce=33d3d9d8e82c331dd877b6c5f4ed52ba;color=#FF0000;display-name=daraz1505;emotes=;flags=;historical=1;id=a36cddd8-06ba-4aed-b693-f503adb97010;mod=0;rm-received-ts=1596061057504;room-id=71092938;subscriber=1;tmi-sent-ts=1596061057059;turbo=0;user-id=171679991;user-type= :daraz1505!daraz1505@daraz1505.tmi.twitch.tv PRIVMSG #xqcow :monkaW ????????",
"@badge-info=subscriber/1;badges=subscriber/0,glhf-pledge/1;color=#FF69B4;display-name=prospector07;emote-only=1;emotes=1035681:0-3,5-8,10-13;flags=;historical=1;id=559b9ccd-11b5-472c-83ce-e16a66fc7533;mod=0;rm-received-ts=1596061057607;room-id=71092938;subscriber=1;tmi-sent-ts=1596061057234;turbo=0;user-id=531980156;user-type= :prospector07!prospector07@prospector07.tmi.twitch.tv PRIVMSG #xqcow :xqcH xqcH xqcH",
"@badge-info=subscriber/2;badges=subscriber/2,glhf-pledge/1;client-nonce=299f6ffc0dabe15f806cb4844a2fdebc;color=#9ACD32;display-name=siriwhatsmyname;emotes=;flags=;historical=1;id=fa0856e3-45d7-496e-97bd-93f941fd96ce;mod=0;rm-received-ts=1596061058007;room-id=71092938;subscriber=1;tmi-sent-ts=1596061057535;turbo=0;user-id=208278150;user-type= :siriwhatsmyname!siriwhatsmyname@siriwhatsmyname.tmi.twitch.tv PRIVMSG #xqcow :WEEBSOUT WEEBSOUT WEEBSOUT WEEBSOUT WEEBSOUT WEEBSOUT",
"@badge-info=;badges=;client-nonce=b45518444921abc86bcca74e6f961c31;color=#FF0000;display-name=Scarrov;emotes=;flags=;historical=1;id=05836fc5-76e0-45de-b0be-779c223b160b;mod=0;rm-received-ts=1596061058008;room-id=71092938;subscriber=0;tmi-sent-ts=1596061057664;turbo=0;user-id=195960862;user-type= :scarrov!scarrov@scarrov.tmi.twitch.tv PRIVMSG #xqcow ????????",
"@historical=1;rm-received-ts=1596061229295;room-id=71092938;slow=5 :tmi.twitch.tv ROOMSTATE #xqcow",
"@historical=1;msg-id=slow_on;rm-received-ts=1596061229296 :tmi.twitch.tv NOTICE #xqcow :This room is now in slow mode. You may send messages every 5 seconds.",
"@badge-info=subscriber/29;badges=subscriber/24;color=#7AC2A7;display-name=gw_ua;emotes=;flags=;historical=1;id=3391449d-3427-490f-836b-f5b8c1c98b93;mod=0;rm-deleted=1;rm-received-ts=1596059993412;room-id=71092938;subscriber=1;tmi-sent-ts=1596059993026;turbo=0;user-id=81302568;user-type= :gw_ua!gw_ua@gw_ua.tmi.twitch.tv PRIVMSG #xqcow :gn i guess",
"@historical=1;login=gw_ua;rm-received-ts=1596061327989;room-id=;target-msg-id=3391449d-3427-490f-836b-f5b8c1c98b93;tmi-sent-ts=1596061327703 :tmi.twitch.tv CLEARMSG #xqcow :gn i guess",
],
"error": null,
"error_code": null
} Returns up to 800 messages. Messages are ordered oldest-to-newest.
Messages are retured in raw IRC format, without trailing newline(s). The API returns PRIVMSG, CLEARCHAT, CLEARMSG, USERNOTICE, NOTICE and ROOMSTATE messages.
All messages returned carry the historical=1 tag.
In addition to the IRC tags originally sent by the Twitch IRC server, all
messages additionally carry the rm-received-ts tag. Its format
is similar to the tmi-sent-ts tag sent by Twitch on some
message types (the value is a timestamp, it contains the number of
milliseconds since Jan 01 1970 00:00:00 UTC, the unix epoch). The
difference/advantage of the rm-received-ts tag is that it is
present on all messages, allowing clients to use it like one would use
the current clock time when receiving normal messages.
Messages that were deleted by some moderation action additionally carry the rm-deleted=1 tag. Note that although typically one would only
consider PRIVMSG and USERNOTICE messages to be
something that "can be deleted", the rm-deleted=1 can actually be
placed on every type of message, as a result of a moderator clearing the entire
chat.
Please also note that my implementation may re-order the tags. For this
reason, you must not rely on IRCv3 tags in the message to be in any
particular order. Please see the standard for further caveats, especially these: "The ordering of tags is not meaningful.",
and: "Implementations MUST interpret empty tag values (e.g. foo=) as equivalent to missing tag values (e.g. foo). Specifications MUST NOT differentiate meaning between
tags with empty and missing values."
Lastly, please ensure that you are parsing the listed messages with an RFC 2812-compliant IRC message parser. You must especially not rely on the last
parameter being marked as "trailing", since the ":" character
marking the last parameter of the IRC message will be omitted should it not
be necessary to form a valid message. (Quoting from the spec: "After
extracting the parameter list, all parameters are equal whether matched by
<middle> or <trailing>. <trailing> is just a syntactic
trick to allow SPACE within the parameter.") For example, this is a message
as you might find it in the API response of this service:
@user-id=132532813;badge-info=;badges=turbo/1;tmi-sent-ts=1673907853307;mod=0;historical=1;returning-chatter=0;flags=;color=#EF8A12;subscriber=0;rm-received-ts=1673907853790;user-type=;display-name=icelys;room-id=11148817;emotes=;turbo=1;id=c220d6d3-6a55-403f-9094-94a80ae2cdcd;first-msg=0 :icelys!icelys@icelys.tmi.twitch.tv PRIVMSG #pajlada FeelsBadMan Note the non-deterministic order of the tags as well as the lack of a ":" character before the "FeelsBadMan".
If you are going to integrate the returned messages into a chat application that also connects to real chat at the same time, it's advisable to filter duplicate messages (messages that your chat client already received "live" that were also returned by the API). Your best bet is to base this on a "weak equality": Check for strict equality between the parsed IRC messages, but allow extra tags on the recent-messages one. (There is no guarantee that the tags documented here might not be extended one day)
The error and error_code parameters are either
both null or both set to some string value.
Despite their name, if error and error_code are
not null, it does not signifiy a hard failure of the request. The API will
still normally return messages. Most applications should therefore ignore the error parameter and also not show it to users. Its presence is purely informational.
error is a readable error message, however it is not meant to
be shown to the user. error_code is a machine-readable error code
string.
Currently, the only valid error_code is channel_not_joined, which signifies that the service is
currently not listening to messages in that channel. This error can arise
when recent messages are requested for nonexistant/deleted/suspended
channels, and it will also be returned if this request is the first request
for that channel. However there are many more combinations of internal
events that can cause ta channel to currently not be joined, such as a
service restart, a reconnect, etc.
Errors
If the provided channel is blacklisted from the service (ignored), HTTP Status Code 403 is returned with the following body:
{
"status": 403,
"status_message": "Forbidden",
"error": "The channel login `randers` is excluded from this service",
"error_code": "channel_ignored"
} If the provided channel name is of invalid format, HTTP Status Code 400 is returned with the following body:
{
"status": 400,
"status_message": "Bad Request",
"error": "Invalid channel login `this_name_is_way_tooooo_long`",
"error_code": "invalid_channel_login"
}