Skip to content

Commit

Permalink
Merge pull request #3 from SharkFourSix/master
Browse files Browse the repository at this point in the history
Add timeount configuration ⏰
  • Loading branch information
zikani03 authored Jul 8, 2022
2 parents 0ca596c + 688602c commit 66734ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ ENV/

# mypy
.mypy_cache/

.vscode/
dialoguss
11 changes: 9 additions & 2 deletions dialoguss.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ type Session struct {
url string
client *http.Client
ApiType string
Timeout time.Duration
}

type DialogussConfig struct {
URL string `yaml:"url"`
Dial string `yaml:"dial"`
PhoneNumber string `yaml:"phoneNumber"`
Sessions []Session `yaml:"sessions"`
Timeout int `yaml:"timeout"`
}

/// AddStep adds step to session
Expand All @@ -112,6 +114,10 @@ func NewInteractiveSession(d DialogussConfig) *Session {
if trurouteMode {
apiType = ApiTypeTruroute
}
var sessionTimeout = defaultTimeout
if d.Timeout > 0 {
sessionTimeout = time.Duration(d.Timeout) * time.Second
}
return &Session{
ID: fmt.Sprintf("DialogussSession__%d", rand.Uint64()),
PhoneNumber: d.PhoneNumber,
Expand All @@ -121,6 +127,7 @@ func NewInteractiveSession(d DialogussConfig) *Session {
url: d.URL,
client: &http.Client{},
ApiType: apiType,
Timeout: sessionTimeout,
}
}

Expand Down Expand Up @@ -197,7 +204,7 @@ sessionLoop:
select {
case value := <-inputCh:
input = value
case <-time.After(defaultTimeout):
case <-time.After(s.Timeout):
fmt.Println("Session timed out!")
break sessionLoop
}
Expand Down Expand Up @@ -227,7 +234,7 @@ type Dialoguss struct {

/// LoadConfig loads configuration from YAML
func (d *Dialoguss) LoadConfig() error {
d.config = DialogussConfig{}
d.config = DialogussConfig{Timeout: int(defaultTimeout)}
b, err := ioutil.ReadFile(d.file)
if err != nil {
return err
Expand Down

0 comments on commit 66734ff

Please sign in to comment.