11import express from 'express' ;
22import { GraphQLList , GraphQLObjectType , GraphQLSchema , GraphQLString } from 'graphql' ;
3- import { isNil } from 'lodash' ;
43import { Inject } from 'noicejs' ;
54
65import { INJECT_CLOCK , INJECT_SERVICES } from '../../BaseService' ;
76import { BotService , BotServiceData , BotServiceOptions , INJECT_BOT , INJECT_STORAGE } from '../../BotService' ;
87import { 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' ;
109import { GRAPH_INPUT_MESSAGE , GRAPH_OUTPUT_MESSAGE , Message } from '../../entity/Message' ;
11- import { SessionRequiredError } from '../../error/SessionRequiredError ' ;
10+ import { getRequestContext } from '../../listener/ExpressListener ' ;
1211import { ServiceModule } from '../../module/ServiceModule' ;
1312import { GRAPH_OUTPUT_SERVICE , ServiceMetadata } from '../../Service' ;
1413import { Storage } from '../../storage' ;
@@ -74,13 +73,9 @@ export class GraphSchema extends BotService<GraphSchemaData> {
7473 }
7574
7675 public async executeCommands ( args : GraphCommandOptions , req : express . Request ) {
77- const context = req . user as Context | undefined ;
76+ const context = getRequestContext ( req ) ;
7877 this . logger . debug ( { args, context } , 'execute commands' ) ;
7978
80- if ( isNil ( context ) ) {
81- throw new SessionRequiredError ( ) ;
82- }
83-
8479 const commands = [ ] ;
8580 for ( const data of args . commands ) {
8681 const { noun, verb } = data ;
@@ -97,13 +92,9 @@ export class GraphSchema extends BotService<GraphSchemaData> {
9792 }
9893
9994 public async sendMessages ( args : GraphMessageOptions , req : express . Request ) {
100- const context = req . user as Context | undefined ;
95+ const context = getRequestContext ( req ) ;
10196 this . logger . debug ( { args, context } , 'send messages' ) ;
10297
103- if ( isNil ( context ) ) {
104- throw new SessionRequiredError ( ) ;
105- }
106-
10798 const messages = [ ] ;
10899 for ( const data of args . messages ) {
109100 const { body, type } = data ;
0 commit comments