diff --git a/packages/security.gblib/models/index.ts b/packages/security.gblib/models/index.ts index 2cb49ce8..c03f6bae 100644 --- a/packages/security.gblib/models/index.ts +++ b/packages/security.gblib/models/index.ts @@ -77,6 +77,13 @@ export class GuaribasUser extends Model { @BelongsTo(() => GuaribasInstance) public instance: GuaribasInstance; + + @Column + phone: string + + @Column(DataType.TEXT) + @Column + conversationReference: string } /** diff --git a/packages/security.gblib/services/SecService.ts b/packages/security.gblib/services/SecService.ts index 358da06b..6ec46e25 100644 --- a/packages/security.gblib/services/SecService.ts +++ b/packages/security.gblib/services/SecService.ts @@ -3,6 +3,7 @@ import urlJoin = require('url-join'); import { GBService, IGBInstance } from 'botlib'; import { GuaribasGroup, GuaribasUser, GuaribasUserGroup } from '../models'; +import { ConversationReference } from 'botbuilder'; /** * Security service layer. @@ -65,4 +66,26 @@ export class SecService extends GBService { .error(reject); }); } + + /** + * Retrives a conversation reference from contact phone. + */ + public async getConversationReference(phone: string): Promise { + const options = { where: { phone: phone } }; + const user = await GuaribasUser.findOne(options); + + return JSON.parse(user.conversationReference); + } + + /** + * Updates a conversation reference from contact phone. + */ + public async updateConversationReference(phone: string, conversationReference: string) { + const options = { where: { phone: phone } }; + const user = await GuaribasUser.findOne(options); + + user.conversationReference = conversationReference; + await user.save(); + } + }