File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed
src/Nullinside.Api.TwitchBot/Controllers Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -31,18 +31,30 @@ public class TwitchWebHookController : ControllerBase {
31
31
[ HttpPost ]
32
32
[ Route ( "chat" ) ]
33
33
public async Task < ContentResult > TwitchChatMessageCallback ( CancellationToken token ) {
34
- using StreamReader stream = new StreamReader ( this . HttpContext . Request . Body ) ;
35
- string stuff = await stream . ReadToEndAsync ( token ) ;
36
- _log . Info ( $ "TwitchChatMessageCallback: { stuff } ") ;
37
-
38
- var hi = JsonConvert . DeserializeObject < TwitchChallangeResponse > ( stuff ) ;
39
- var resp = new ContentResult ( ) ;
40
- resp . ContentType = "text/plain" ;
41
- resp . StatusCode = ( int ) HttpStatusCode . OK ;
42
- if ( null != hi ) {
43
- resp . Content = hi . Challenge ? . ToString ( ) ?? string . Empty ;
34
+ var body = await this . GetBodyAsString ( token ) ;
35
+ var resp = new ContentResult {
36
+ ContentType = "text/plain" ,
37
+ StatusCode = ( int ) HttpStatusCode . OK
38
+ } ;
39
+
40
+ _log . Info ( $ "TwitchChatMessageCallback: { body } ") ;
41
+
42
+ var messageType = GetTwitchMessageType ( ) ;
43
+ switch ( messageType ) {
44
+ case "webhook_callback_verification" :
45
+ var challenge = JsonConvert . DeserializeObject < TwitchChallangeResponse > ( body ) ;
46
+ if ( null != challenge ) {
47
+ resp . ContentType = "text/plain" ;
48
+ resp . Content = challenge . Challenge ? . ToString ( ) ?? string . Empty ;
49
+ }
50
+
51
+ break ;
44
52
}
45
53
46
54
return resp ;
47
55
}
56
+
57
+ private string ? GetTwitchMessageType ( ) {
58
+ return this . Request . Headers [ "Twitch-Eventsub-Message-Type" ] ;
59
+ }
48
60
}
You can’t perform that action at this time.
0 commit comments