2021-02-23 12:19:24 +02:00
|
|
|
# Line Usage
|
|
|
|
|
|
|
|
Install notifier using:
|
|
|
|
|
|
|
|
* `go get -u github.com/nikoksr/notify`
|
|
|
|
|
|
|
|
|
|
|
|
## Sample Code
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nikoksr/notify"
|
|
|
|
"github.com/nikoksr/notify/service/line"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Assuming you already have a line messaging API credential
|
|
|
|
// Provide your channel secret and access token
|
|
|
|
lineService, _ := line.New("channelSecret", "channelAccessToken")
|
|
|
|
|
|
|
|
// Add id from various receivers
|
|
|
|
// You can try to use your own line id for testing
|
|
|
|
lineService.AddReceivers("userID1", "groupID1")
|
|
|
|
|
|
|
|
notifier := notify.New()
|
2021-03-06 16:03:52 +02:00
|
|
|
|
2021-02-23 12:19:24 +02:00
|
|
|
// Tell our notifier to use the line service. You can repeat the above process
|
|
|
|
// for as many services as you like and just tell the notifier to use them.
|
|
|
|
notifier.UseServices(lineService)
|
|
|
|
|
|
|
|
// Send a message
|
2021-03-06 16:03:52 +02:00
|
|
|
err := notifier.Send(
|
|
|
|
context.Background(),
|
2021-02-23 12:19:24 +02:00
|
|
|
"Welcome",
|
|
|
|
"I am a bot written in Go!",
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-23 13:25:35 +02:00
|
|
|
|
|
|
|
## Sample Code for Line Notify
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nikoksr/notify"
|
|
|
|
"github.com/nikoksr/notify/service/line"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Assuming you already have a line messaging API credential
|
|
|
|
// Provide your channel secret and access token
|
|
|
|
lineNotifyService := line.NewNotify()
|
|
|
|
|
|
|
|
// Add id from various receivers
|
|
|
|
// You can try to use your own line id for testing
|
|
|
|
lineNotifyService.AddReceivers("receiverToken")
|
|
|
|
|
|
|
|
notifier := notify.New()
|
|
|
|
|
|
|
|
// Tell our notifier to use the line service. You can repeat the above process
|
|
|
|
// for as many services as you like and just tell the notifier to use them.
|
|
|
|
notifier.UseServices(lineNotifyService)
|
|
|
|
|
|
|
|
// Send a message
|
|
|
|
err := notifier.Send(
|
|
|
|
context.Background(),
|
|
|
|
"Welcome",
|
|
|
|
"I am a bot written in Go!",
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|