Skip to content

Commit

Permalink
Merge pull request #102 from oklahomer/v3.0.0
Browse files Browse the repository at this point in the history
Go in peace. Aug. 15th.
  • Loading branch information
oklahomer authored Aug 15, 2020
2 parents 6b86598 + 4fee191 commit 54f7ea3
Show file tree
Hide file tree
Showing 47 changed files with 1,598 additions and 1,344 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ An adapter developer may focus on implementing the protocol to interacting with
To take a look at those components and their relations, see [Components](https://github.com/oklahomer/go-sarah/wiki/Components).

# IMPORTANT NOTICE
This is the second major version of `go-sarah`. If you are using the previous version of it, take a look at [Migrating from v1.x to v2.x](https://github.com/oklahomer/go-sarah/wiki/Migrating-from-v1.x-to-v2.x) to migrate to the newer version.
## v3 Release
This is the third major version of `go-sarah`, which introduces the Slack adapter's improvement to support both RTM and Events API.
Breaking interface change for Slack adapter was inevitable and that is the sole reason for this major version up.
Other than that, this does not include any breaking change.
See [Migrating from v2.x to v3.x](https://github.com/oklahomer/go-sarah/wiki/Migrating-from-v2.x-to-v3.x) for details.

## v2 Release
The second major version introduced some breaking changes to `go-sarah`.
This version still supports and maintains all functionalities, better interfaces for easier integration are added.
See [Migrating from v1.x to v2.x](https://github.com/oklahomer/go-sarah/wiki/Migrating-from-v1.x-to-v2.x) to migrate from the older version.

# Supported Chat Services/Protocols
Although a developer may implement `sarah.Adapter` to integrate with the desired chat service,
Expand Down Expand Up @@ -61,8 +70,8 @@ package main
import (
"context"
"fmt"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/slack"

"os"
"os/signal"
Expand Down Expand Up @@ -102,7 +111,7 @@ func setupSlack() {
// Setup slack adapter.
slackConfig := slack.NewConfig()
slackConfig.Token = "REPLACE THIS"
adapter, err := slack.NewAdapter(slackConfig)
adapter, err := slack.NewAdapter(slackConfig, slack.WithRTMPayloadHandler(slack.DefaultRTMPayloadHandler))
if err != nil {
panic(fmt.Errorf("faileld to setup Slack Adapter: %s", err.Error()))
}
Expand All @@ -127,8 +136,8 @@ package guess

import (
"context"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/slack"
"math/rand"
"strconv"
"strings"
Expand Down Expand Up @@ -189,8 +198,8 @@ package hello

import (
"context"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/slack"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion alerter/line/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package line
import (
"context"
"fmt"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v3"
"golang.org/x/xerrors"
"net/http"
"net/url"
Expand Down
2 changes: 1 addition & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sarah

import (
"context"
"github.com/oklahomer/go-sarah/v2/log"
"github.com/oklahomer/go-sarah/v3/log"
)

// Bot provides an interface that each bot implementation must satisfy.
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sarah

import (
"context"
"github.com/oklahomer/go-sarah/v2/log"
"github.com/oklahomer/go-sarah/v3/log"
"golang.org/x/xerrors"
"reflect"
"regexp"
Expand Down
205 changes: 101 additions & 104 deletions doc/uml/components.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Id,Name,Shape Library,Page ID,Contained By,Group,Line Source,Line Destination,So
7,Database,Flowchart Shapes,1,,,,,,,sarah.UserContextStorage,
8,Component,UML,1,,,,,,,.echo command,
9,Component,UML,1,,,,,,,.weather command,
10,Actor,UML,1,,,,,,,Actor,
10,Actor,UML,1,,,,,,,User,
11,Cloud,Geometric Shapes,1,,,,,,,Chat Service,
12,Circle,Geometric Shapes,1,,,,,,,,
13,Circle,Geometric Shapes,1,,,,,,,,
Expand All @@ -28,117 +28,114 @@ Id,Name,Shape Library,Page ID,Contained By,Group,Line Source,Line Destination,So
27,Component,UML,1,,,,,,,alarmTaskProps,
28,Component,UML,1,,,,,,,echoProps,
29,Component,UML,1,,,,,,,weatherProps,
30,Actor,UML,1,,,,,,,Actor,
30,Actor,UML,1,,,,,,,Admin,
31,Cloud,Geometric Shapes,1,,,,,,,,
32,Object,UML,1,,,,,,,alarm.cnf,
33,Object,UML,1,,,,,,,weather.cnf,
34,Start,UML,1,,,,,,,,
35,Package,UML,1,,,,,,,sarah.scheduler,
36,Note,Standard,1,,,,,,,Supervise queue length,
37,Text,Standard,1,,,,,,,Input message,
38,Note,Standard,1,,,,,,,"Receive service specific message
Converts it ti sarah.Input implementation",
39,Text,Standard,1,,,,,,,Respond,
40,Note,Standard,1,,,,,,,"func(sarah.Input) error
Receives input and passes it to internal worker",
41,Text,Standard,1,,,,,,,Worker.Enqueue(),
42,Text,Standard,1,,,,,,,Bot.Respond(),
43,Text,Standard,1,,,,,,,cron.Cron,
44,Text,Standard,1,,,,,,,Execute ScheduledTask,
45,Text,Standard,1,,,,,,,Update configuration,
46,Direct Access Storage (Hard Disk),Flowchart Shapes,1,,,,,,,chan error,
47,Package,UML,1,,,,,,,sarah.alerters,
48,Circle,Geometric Shapes,1,,,,,,,cron,
49,Cloud,Geometric Shapes,1,,,,,,,Alerting service,
50,Text,Standard,1,,,,,,,alerters.alertAll(),
51,Note,Standard,1,,,,,,,"Receives critical errors
36,DefaultNoteBlockV2,Standard,1,,,,,,,"Receive service specific message
Convert it to sarah.Input implementation",
37,DefaultNoteBlockV2,Standard,1,,,,,,,"A function provided to each Bot by go-sarah's core
to receive incoming payload and pass it to internal worker",
38,Text,Standard,1,,,,,,,Worker.Enqueue(),
39,Text,Standard,1,,,,,,,Bot.Respond(),
40,Text,Standard,1,,,,,,,cron.Cron,
41,Direct Access Storage (Hard Disk),Flowchart Shapes,1,,,,,,,chan error,
42,Package,UML,1,,,,,,,sarah.alerters,
43,Circle,Geometric Shapes,1,,,,,,,cron,
44,Cloud,Geometric Shapes,1,,,,,,,Alerting Service,
45,Text,Standard,1,,,,,,,alerters.alertAll(),
46,DefaultNoteBlockV2,Standard,1,,,,,,,"Receive critical errors
from all components",
52,Text,Standard,1,,,,,,,Execute,
53,Text,Standard,1,,,,,,,Commands.ExecuteFirstMatched(),
54,Text,Standard,1,,,,,,,Bot.SendMessage(),
55,Text,Standard,1,,,,,,,Send command's response,
56,Note,Standard,1,,,,,,,"Props is a set of arguments to build
47,Text,Standard,1,,,,,,,Commands.ExecuteFirstMatched(),
48,Text,Standard,1,,,,,,,Bot.SendMessage(),
49,DefaultNoteBlockV2,Standard,1,,,,,,,"Props is a set of arguments to build
sarah.Command or sarah.ScheduledTask
on the fly",
57,Text,Standard,1,,,,,,,sarah.ConfigWatcher,
58,Text,Standard,1,,,,,,,Subscribe to
configuration change,
59,Text,Standard,1,,,,,,,"Find corresponding props
to updated configuration",
60,Text,Standard,1,,,,,,,Replace existing task with rebuilt one,
61,Text,Standard,1,,,,,,,Send message,
62,Package,UML,1,,,,,,,sarah.Bot,
63,Circle,Geometric Shapes,1,,,,,,,,
64,Package,UML,1,,,,,,,sarah.Commands,
65,Database,Flowchart Shapes,1,,,,,,,sarah.UserContextStorage,
on the fly.",
50,Text,Standard,1,,,,,,,sarah.ConfigWatcher,
51,Text,Standard,1,,,,,,,,
52,Text,Standard,1,,,,,,,Replace existing task with rebuilt one,
53,Package,UML,1,,,,,,,sarah.Bot,
54,Circle,Geometric Shapes,1,,,,,,,,
55,Package,UML,1,,,,,,,sarah.Commands,
56,Database,Flowchart Shapes,1,,,,,,,sarah.UserContextStorage,
57,Circle,Geometric Shapes,1,,,,,,,,
58,Text,Standard,1,,,,,,,Bot.Respond(),
59,Circle,Geometric Shapes,1,,,,,,,,
60,Text,Standard,1,,,,,,,Commands.ExecuteFirstMatched(),
61,Text,Standard,1,,,,,,,Bot.SendMessage(),
62,Circle,Geometric Shapes,1,,,,,,,,
63,Cloud,Geometric Shapes,1,,,,,,,Chat Service,
64,Actor,UML,1,,,,,,,User,
65,Circle,Geometric Shapes,1,,,,,,,,
66,Circle,Geometric Shapes,1,,,,,,,,
67,Text,Standard,1,,,,,,,Bot.Respond(),
68,Circle,Geometric Shapes,1,,,,,,,,
69,Text,Standard,1,,,,,,,Commands.ExecuteFirstMatched(),
70,Text,Standard,1,,,,,,,Bot.SendMessage(),
71,Circle,Geometric Shapes,1,,,,,,,,
72,Cloud,Geometric Shapes,1,,,,,,,Chat Service,
73,Actor,UML,1,,,,,,,Actor,
74,Circle,Geometric Shapes,1,,,,,,,,
75,Circle,Geometric Shapes,1,,,,,,,,
76,Circle,Geometric Shapes,1,,,,,,,,
77,Note,Standard,1,,,,,,,"Multiple sara.Bot instanses
can be rune in one process",
78,Note,Standard,1,,,,,,,"Variety of configuration management system can be treated
67,Circle,Geometric Shapes,1,,,,,,,,
68,DefaultNoteBlockV2,Standard,1,,,,,,,"Multiple sarah.Bot instanses
can be rune in one process.",
69,DefaultNoteBlockV2,Standard,1,,,,,,,"Variety of configuration management systems can be treated
including file system, HashiCorp's Consul, LINE's Central Dogma, etc...",
79,Text,Standard,1,,,,,,,Illustration of go-sarah's Major Components,
80,Note,Standard,1,,,,,,,"- Receive sarah.Input
70,Text,Standard,1,,,,,,,Illustration of go-sarah's Major Components,
71,DefaultNoteBlockV2,Standard,1,,,,,,,"- Receive sarah.Input
- Fetch usre's state from context storage
- If found, execute the next step with given Input
- If not, find corresponding Command for given Input
- Call Bot.SendMessage() to send output

",
81,Text,Standard,1,,,,,,,Subscribe to changes,
82,Circle,Geometric Shapes,1,,,,,,,cron,
83,Text,Standard,1,,,,,,,Update task schedule,
84,Note,Standard,1,,,,,,,"Manage task schedduls.
While sarah.Commands are executed against user input, sarah.ScheduledTasks are executed in a scheduled manner.",
85,Note,Standard,1,,,,,,,"Slack message, e-mail, LINE message, etc...
Anything can be used as long as the protocol is implemented by sarah.Alerter implementation",
86,Line,,1,,,,12,None,Arrow,,
87,Line,,1,,,12,14,None,Arrow,,
88,Line,,1,,,14,15,None,Arrow,,
89,Line,,1,,,15,16,None,Arrow,,
90,Line,,1,,,16,6,None,Arrow,,
91,Line,,1,,,6,18,None,Arrow,,
92,Line,,1,,,18,19,None,Arrow,,
93,Line,,1,,,19,63,None,Arrow,,
94,Line,,1,,,19,20,None,Arrow,,
95,Line,,1,,,19,7,None,Arrow,,
96,Line,,1,,,63,13,None,Arrow,,
97,Line,,1,,,13,,None,Arrow,,
98,Line,,1,,,21,6,None,Arrow,,
99,Line,,1,,,34,32,None,Arrow,,
100,Line,,1,,,34,27,None,Arrow,,
101,Line,,1,,,26,23,None,Arrow,,
102,Line,,1,,,23,63,None,Arrow,,
103,Line,,1,,,,32,None,Arrow,,
104,Line,,1,,,82,22,None,Arrow,,
105,Line,,1,,,38,14,None,Arrow,,
106,Line,,1,,,40,15,None,Arrow,,
107,Line,,1,,,46,48,None,Arrow,,
108,Line,,1,,,49,,None,Arrow,,
109,Line,,1,,,48,49,None,Arrow,,
110,Line,,1,,,51,46,None,Arrow,,
111,Line,,1,,,20,8,None,Arrow,,
112,Line,,1,,,80,19,None,Arrow,,
113,Line,,1,,,,24,None,Arrow,,
114,Line,,1,,,73,73,None,None,,
115,Line,,1,,,75,74,None,Arrow,,
116,Line,,1,,,71,76,None,Arrow,,
117,Line,,1,,,18,66,None,Arrow,,
118,Line,,1,,,74,15,None,Arrow,,
119,Line,,1,,,66,71,None,Arrow,,
120,Line,,1,,,66,65,None,Arrow,,
121,Line,,1,,,66,68,None,Arrow,,
122,Line,,1,,,,75,None,Arrow,,
123,Line,,1,,,76,,None,Arrow,,
124,Line,,1,,,78,31,None,Arrow,,
125,Line,,1,,,77,62,None,Arrow,,
126,Line,,1,,,26,35,None,Arrow,,
127,Line,,1,,,84,35,None,Arrow,,
128,Line,,1,,,85,49,None,Arrow,,
- If not, find corresponding command for given Input
- Call Bot.SendMessage() to send output",
72,Text,Standard,1,,,,,,,,
73,Circle,Geometric Shapes,1,,,,,,,cron,
74,Text,Standard,1,,,,,,,Update task schedule,
75,DefaultNoteBlockV2,Standard,1,,,,,,,"Manage task schedduls
While sarah.Commands are executed against user input, sarah.ScheduledTasks are executed in a scheduled manner",
76,DefaultNoteBlockV2,Standard,1,,,,,,,"Slack message, e-mail, LINE message, etc...
Anything can be used as long as the protocol is implemented by sarah.Alerter implementation.",
77,Circle,Geometric Shapes,1,,,,,,,,
78,Text,Standard,1,,,,,,,"func(BotType, error) *SupervisionDirective",
79,DefaultNoteBlockV2,Standard,1,,,,,,,"Judge if the error indicates the fatal state of the Bot, and returns how to treat such state",
80,Text,Standard,1,,,,,,,func(sarah.Input) error,
81,Line,,1,,,,12,None,Arrow,Input message,
82,Line,,1,,,12,14,None,Arrow,,
83,Line,,1,,,14,15,None,Arrow,,
84,Line,,1,,,15,16,None,Arrow,,
85,Line,,1,,,16,6,None,Arrow,,
86,Line,,1,,,6,18,None,Arrow,,
87,Line,,1,,,18,19,None,Arrow,,
88,Line,,1,,,19,54,None,Arrow,Send command's response,
89,Line,,1,,,19,20,None,Arrow,,
90,Line,,1,,,19,7,None,Arrow,,
91,Line,,1,,,54,13,None,Arrow,Send message,
92,Line,,1,,,13,,None,Arrow,Respond,
93,Line,,1,,,21,6,None,Arrow,Supervise queue length,
94,Line,,1,,,34,32,None,Arrow,Subscribe to changes,
95,Line,,1,,,34,27,None,Arrow,"Find corresponding props
to updated configuration",
96,Line,,1,,,26,52,None,None,,
97,Line,,1,,,52,23,None,Arrow,,
98,Line,,1,,,23,54,None,Arrow,,
99,Line,,1,,,,32,None,Arrow,Update configuration,
100,Line,,1,,,73,22,None,Arrow,Execute ScheduledTask,
101,Line,,1,,,36,14,None,Arrow,,
102,Line,,1,,,37,15,None,Arrow,,
103,Line,,1,,,41,77,None,Arrow,,
104,Line,,1,,,44,,None,Arrow,,
105,Line,,1,,,43,44,None,Arrow,Notify error state,
106,Line,,1,,,46,41,None,Arrow,,
107,Line,,1,,,20,8,None,Arrow,Execute,
108,Line,,1,,,71,19,None,Arrow,,
109,Line,,1,,,49,24,None,Arrow,,
110,Line,,1,,,64,64,None,None,,
111,Line,,1,,,66,65,None,Arrow,,
112,Line,,1,,,62,67,None,Arrow,,
113,Line,,1,,,18,57,None,Arrow,,
114,Line,,1,,,65,15,None,Arrow,,
115,Line,,1,,,57,62,None,Arrow,,
116,Line,,1,,,57,56,None,Arrow,,
117,Line,,1,,,57,59,None,Arrow,,
118,Line,,1,,,,66,None,Arrow,,
119,Line,,1,,,67,,None,Arrow,,
120,Line,,1,,,69,31,None,Arrow,,
121,Line,,1,,,68,53,None,Arrow,,
122,Line,,1,,,74,35,None,Arrow,,
123,Line,,1,,,26,74,None,None,,
124,Line,,1,,,75,35,None,Arrow,,
125,Line,,1,,,76,44,None,Arrow,,
126,Line,,1,,,77,43,None,Arrow,,
127,Line,,1,,,79,77,None,Arrow,,
Binary file modified doc/uml/components.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/uml/components.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 15 additions & 14 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ package main
import (
"context"
"flag"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/alerter/line"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/count"
"github.com/oklahomer/go-sarah/v2/examples/simple/plugins/echo"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/fixedtimer"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/guess"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/hello"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/morning"
_ "github.com/oklahomer/go-sarah/v2/examples/simple/plugins/timer"
"github.com/oklahomer/go-sarah/v2/examples/simple/plugins/todo"
"github.com/oklahomer/go-sarah/v2/log"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v2/watchers"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/alerter/line"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/count"
"github.com/oklahomer/go-sarah/v3/examples/simple/plugins/echo"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/fixedtimer"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/guess"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/hello"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/morning"
_ "github.com/oklahomer/go-sarah/v3/examples/simple/plugins/timer"
"github.com/oklahomer/go-sarah/v3/examples/simple/plugins/todo"
"github.com/oklahomer/go-sarah/v3/log"
"github.com/oklahomer/go-sarah/v3/slack"
"github.com/oklahomer/go-sarah/v3/watchers"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
Expand Down Expand Up @@ -115,7 +115,8 @@ func readConfig(path string) *myConfig {
}

func setupSlack(config *slack.Config, storage sarah.UserContextStorage) {
adapter, err := slack.NewAdapter(config)
//adapter, err := slack.NewAdapter(config, slack.WithEventsPayloadHandler(slack.DefaultEventsPayloadHandler))
adapter, err := slack.NewAdapter(config, slack.WithRTMPayloadHandler(slack.DefaultRTMPayloadHandler))
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/simple/plugins/count/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package count
import (
"context"
"fmt"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/gitter"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/gitter"
"github.com/oklahomer/go-sarah/v3/slack"
"regexp"
"sync"
)
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/plugins/echo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ package echo

import (
"context"
"github.com/oklahomer/go-sarah/v2"
"github.com/oklahomer/go-sarah/v2/slack"
"github.com/oklahomer/go-sarah/v3"
"github.com/oklahomer/go-sarah/v3/slack"
"regexp"
)

Expand Down
Loading

0 comments on commit 54f7ea3

Please sign in to comment.