@@ -7,6 +7,7 @@ import { IAgentRuntime, ModelClass } from "@ai16z/eliza/src/types.ts";
7
7
import { stringToUuid } from "@ai16z/eliza/src/uuid.ts" ;
8
8
import { ClientBase } from "./base.ts" ;
9
9
import { ApprovalQueue } from './approval-queue.js' ;
10
+ import { WebApprovalInterface } from './web/approval-interface.js' ;
10
11
11
12
const twitterPostTemplate = `{{timeline}}
12
13
@@ -27,35 +28,38 @@ Your response should not contain any questions. Brief, concise statements only.
27
28
28
29
export class TwitterPostClient extends ClientBase {
29
30
private approvalQueue : ApprovalQueue ;
30
- private approvalInterface : any ; // Will be WebApprovalInterface
31
+ private approvalInterface : WebApprovalInterface | null = null ;
31
32
32
33
onReady ( ) {
33
34
const generateNewTweetLoop = ( ) => {
34
35
this . generateNewTweet ( ) ;
35
36
setTimeout (
36
37
generateNewTweetLoop ,
37
38
( Math . floor ( Math . random ( ) * ( 20 - 2 + 1 ) ) + 2 ) * 60 * 1000
38
- ) ; // Random interval between 4-8 hours
39
+ ) ;
39
40
} ;
40
41
generateNewTweetLoop ( ) ;
41
42
}
42
43
43
44
constructor ( runtime : IAgentRuntime ) {
44
- // Initialize the client and pass an optional callback to be called when the client is ready
45
45
super ( {
46
46
runtime,
47
47
} ) ;
48
48
this . approvalQueue = new ApprovalQueue ( undefined , this . config . approvalTimeout ) ;
49
49
50
50
// Initialize and start the approval interface if required
51
51
if ( this . config . approvalRequired ) {
52
- import ( './web/approval-interface.js' ) . then ( async ( { WebApprovalInterface } ) => {
53
- this . approvalInterface = await WebApprovalInterface . create ( undefined , 3000 ) ;
54
- await this . approvalInterface . start ( ) ;
55
- console . log ( 'Twitter approval interface initialized and started' ) ;
56
- } ) . catch ( error => {
57
- console . error ( 'Error initializing approval interface:' , error ) ;
58
- } ) ;
52
+ this . initializeApprovalInterface ( ) ;
53
+ }
54
+ }
55
+
56
+ private async initializeApprovalInterface ( ) {
57
+ try {
58
+ this . approvalInterface = new WebApprovalInterface ( this . approvalQueue , 3000 ) ;
59
+ await this . approvalInterface . start ( ) ;
60
+ console . log ( 'Twitter approval interface initialized and started at http://localhost:3000/twitter-approval' ) ;
61
+ } catch ( error ) {
62
+ console . error ( 'Error initializing approval interface:' , error ) ;
59
63
}
60
64
}
61
65
0 commit comments