mirror of https://github.com/msgbyte/tailchat
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			37 lines
		
	
	
		
			851 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			37 lines
		
	
	
		
			851 B
		
	
	
	
		
			TypeScript
		
	
import { TcService, TcPureContext } from 'tailchat-server-sdk';
 | 
						|
import { sleep } from '../lib/utils';
 | 
						|
 | 
						|
export default class TestService extends TcService {
 | 
						|
  get serviceName(): string {
 | 
						|
    return 'debug';
 | 
						|
  }
 | 
						|
 | 
						|
  onInit(): void {
 | 
						|
    this.registerAction('hello', this.echo, {
 | 
						|
      params: {
 | 
						|
        name: [{ type: 'string', optional: true }],
 | 
						|
      },
 | 
						|
    });
 | 
						|
    this.registerAction('sleep', this.sleep, {
 | 
						|
      params: {
 | 
						|
        second: 'number',
 | 
						|
      },
 | 
						|
    });
 | 
						|
  }
 | 
						|
 | 
						|
  // Action
 | 
						|
  echo(ctx: TcPureContext<{ name: string }>): string {
 | 
						|
    console.log(ctx.meta);
 | 
						|
    return `Hello ${
 | 
						|
      ctx.params.name ?? ctx.meta.t('匿名用户')
 | 
						|
    }, \nHere is your meta info: ${JSON.stringify(ctx.meta, null, 2)}`;
 | 
						|
  }
 | 
						|
 | 
						|
  // Action
 | 
						|
  async sleep(ctx: TcPureContext<{ second: number }>) {
 | 
						|
    await sleep(ctx.params.second * 1000);
 | 
						|
 | 
						|
    return true;
 | 
						|
  }
 | 
						|
}
 |