@@ -43,8 +43,10 @@ class Node {
43
43
export class SettingsMemoryScope extends MemoryScope {
44
44
/**
45
45
* Initializes a new instance of the [SettingsMemoryScope](xref:botbuilder-dialogs.SettingsMemoryScope) class.
46
+ *
47
+ * @param initialSettings initial set of settings to supply
46
48
*/
47
- public constructor ( ) {
49
+ public constructor ( private readonly initialSettings ?: Record < string , unknown > ) {
48
50
super ( ScopePath . settings , false ) ;
49
51
}
50
52
@@ -57,19 +59,27 @@ export class SettingsMemoryScope extends MemoryScope {
57
59
public getMemory ( dc : DialogContext ) : Record < string , unknown > {
58
60
if ( dc . context . turnState . has ( ScopePath . settings ) ) {
59
61
return dc . context . turnState . get ( ScopePath . settings ) ?? { } ;
60
- } else {
61
- const configuration = dc . context . turnState . get ( DialogTurnStateConstants . configuration ) ?? { } ;
62
+ }
63
+
64
+ const configuration = dc . context . turnState . get ( DialogTurnStateConstants . configuration ) ?? { } ;
65
+
66
+ Object . entries ( process . env ) . reduce ( ( result , [ key , value ] ) => {
67
+ result [ `${ key } ` ] = value ;
68
+ return result ;
69
+ } , configuration ) ;
62
70
63
- Object . entries ( process . env ) . reduce ( ( result , [ key , value ] ) => {
64
- result [ `${ key } ` ] = value ;
65
- return result ;
66
- } , configuration ) ;
71
+ const settings = SettingsMemoryScope . loadSettings ( configuration ) ;
72
+ dc . context . turnState . set ( ScopePath . settings , settings ) ;
67
73
68
- const settings = SettingsMemoryScope . loadSettings ( configuration ) ;
69
- dc . context . turnState . set ( ScopePath . settings , settings ) ;
74
+ return settings ;
75
+ }
70
76
71
- return settings ;
77
+ public async load ( dc : DialogContext ) : Promise < void > {
78
+ if ( this . initialSettings ) {
79
+ dc . context . turnState . set ( ScopePath . settings , this . initialSettings ) ;
72
80
}
81
+
82
+ await super . load ( dc ) ;
73
83
}
74
84
75
85
/**
@@ -79,15 +89,15 @@ export class SettingsMemoryScope extends MemoryScope {
79
89
* @returns {Record<string, ?> } Projected dictionary for settings.
80
90
*/
81
91
protected static loadSettings ( configuration : Record < string , string > ) : Record < string , unknown > {
82
- const settings = { } ;
92
+ let settings = { } ;
83
93
84
94
if ( configuration ) {
85
95
// load configuration into settings
86
96
const root = this . convertFlattenSettingToNode ( Object . entries ( configuration ) ) ;
87
- root . children . reduce ( ( result , child ) => {
88
- result [ child . value ] = this . convertNodeToObject ( child ) ;
89
- return result ;
90
- } , settings ) ;
97
+ settings = root . children . reduce (
98
+ ( acc , child ) => ( { ... acc , [ child . value ] : this . convertNodeToObject ( child ) } ) ,
99
+ settings
100
+ ) ;
91
101
}
92
102
93
103
return settings ;
0 commit comments