Entities: url, email and other
Handle when user writes some entities (url, email, phone_number, hashtag, and other)
What are entities?
Entity it's part of a message with unique content (e.g. url, email, phone_number, hashtag, cashtag and other). You can read about entity and see all entity types here
Listen to text message with some entity
To listen to a text message with some entity, use @OnEntity
decorator
import { OnEntity, Controller } from 'nestgram';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService?: AppService) {}
@OnEntity('email')
async onEmail(): Promise<string> {
return 'I got your email!';
}
}
Get entity from a text message
To get an entity from a text message, use @Entity parameter decorator, and pass the entity type you want to get
import { OnEntity, Controller, Entity, IEntity } from 'nestgram';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService?: AppService) {}
@OnEntity('email')
async onEmail(@Entity('email') email: IEntity): Promise<string> {
return `I got your email! ${email?.result}`;
}
}
Last updated