1
1
import express from 'express' ;
2
2
import { GraphQLList , GraphQLObjectType , GraphQLSchema , GraphQLString } from 'graphql' ;
3
- import { isNil } from 'lodash' ;
4
3
import { Inject } from 'noicejs' ;
5
4
6
5
import { INJECT_CLOCK , INJECT_SERVICES } from '../../BaseService' ;
7
6
import { BotService , BotServiceData , BotServiceOptions , INJECT_BOT , INJECT_STORAGE } from '../../BotService' ;
8
7
import { Command , CommandVerb , GRAPH_INPUT_COMMAND , GRAPH_OUTPUT_COMMAND } from '../../entity/Command' ;
9
- import { Context , GRAPH_INPUT_CONTEXT } from '../../entity/Context' ;
8
+ import { GRAPH_INPUT_CONTEXT } from '../../entity/Context' ;
10
9
import { GRAPH_INPUT_MESSAGE , GRAPH_OUTPUT_MESSAGE , Message } from '../../entity/Message' ;
11
- import { SessionRequiredError } from '../../error/SessionRequiredError ' ;
10
+ import { getRequestContext } from '../../listener/ExpressListener ' ;
12
11
import { ServiceModule } from '../../module/ServiceModule' ;
13
12
import { GRAPH_OUTPUT_SERVICE , ServiceMetadata } from '../../Service' ;
14
13
import { Storage } from '../../storage' ;
@@ -74,13 +73,9 @@ export class GraphSchema extends BotService<GraphSchemaData> {
74
73
}
75
74
76
75
public async executeCommands ( args : GraphCommandOptions , req : express . Request ) {
77
- const context = req . user as Context | undefined ;
76
+ const context = getRequestContext ( req ) ;
78
77
this . logger . debug ( { args, context } , 'execute commands' ) ;
79
78
80
- if ( isNil ( context ) ) {
81
- throw new SessionRequiredError ( ) ;
82
- }
83
-
84
79
const commands = [ ] ;
85
80
for ( const data of args . commands ) {
86
81
const { noun, verb } = data ;
@@ -97,13 +92,9 @@ export class GraphSchema extends BotService<GraphSchemaData> {
97
92
}
98
93
99
94
public async sendMessages ( args : GraphMessageOptions , req : express . Request ) {
100
- const context = req . user as Context | undefined ;
95
+ const context = getRequestContext ( req ) ;
101
96
this . logger . debug ( { args, context } , 'send messages' ) ;
102
97
103
- if ( isNil ( context ) ) {
104
- throw new SessionRequiredError ( ) ;
105
- }
106
-
107
98
const messages = [ ] ;
108
99
for ( const data of args . messages ) {
109
100
const { body, type } = data ;
0 commit comments