-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from go-microbot/feature/v0.6.0
v0.6.0
- Loading branch information
Showing
11 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
apiModels "github.com/go-microbot/viber/api/models" | ||
) | ||
|
||
// GetOnline represents method to fetch the online status of a given subscribed account members. | ||
// The API supports up to 100 user ID per request and | ||
// those users must be subscribed to the account. | ||
func (api *ViberAPI) GetOnline(ctx context.Context, req apiModels.UserIDsRequest) (*apiModels.GetOnlineResponse, error) { | ||
resp, err := api.NewRequest("get_online"). | ||
Method(http.MethodPost). | ||
Body(NewJSONBody(req)). | ||
Do(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var onlineResp apiModels.GetOnlineResponse | ||
if err := resp.Decode(&onlineResp); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &onlineResp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
apiModels "github.com/go-microbot/viber/api/models" | ||
"github.com/go-microbot/viber/models" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type getOnline struct{} | ||
|
||
func (h getOnline) Test(ctx context.Context, t *testing.T) context.Context { | ||
memberID := ctx.Value(chatMemberIDCtxKey) | ||
require.NotNil(t, memberID) | ||
|
||
online, err := testAPI.GetOnline(ctx, apiModels.UserIDsRequest{ | ||
IDs: []string{memberID.(string)}, | ||
}) | ||
require.NoError(t, err) | ||
require.NotNil(t, online) | ||
require.NotEmpty(t, online.Users) | ||
var found bool | ||
for i := range online.Users { | ||
if online.Users[i].ID == memberID.(string) { | ||
require.True(t, | ||
online.Users[i].OnlineStatus == models.UserOnlineStatusOnline || | ||
online.Users[i].OnlineStatus == models.UserOnlineStatusOffline) | ||
found = true | ||
break | ||
} | ||
} | ||
require.True(t, found) | ||
|
||
return ctx | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package models | ||
|
||
import "github.com/go-microbot/viber/models" | ||
|
||
// GetOnlineResponse represents `get_online` response model. | ||
type GetOnlineResponse struct { | ||
MessageResponse | ||
Users []GetOnlineUser `json:"users"` | ||
} | ||
|
||
// GetOnlineUser represents user online status. | ||
type GetOnlineUser struct { | ||
// Unique Viber user id. | ||
ID string `json:"id"` | ||
// Online status code. | ||
// 0 for online, | ||
// 1 for offline, | ||
// 2 for undisclosed - user set Viber to hide status, | ||
// 3 for try later - internal error, | ||
// 4 for unavailable - not a Viber user/unsubscribed/unregistered. | ||
OnlineStatus models.UserOnlineStatus `json:"online_status"` | ||
// Online status message. | ||
OnlineStatusMessage string `json:"online_status_message"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package models | ||
|
||
// There are available user online statuses. | ||
const ( | ||
UserOnlineStatusOnline UserOnlineStatus = 0 | ||
UserOnlineStatusOffline UserOnlineStatus = 1 | ||
UserOnlineStatusUndisclosed UserOnlineStatus = 2 | ||
UserOnlineStatusInternalError UserOnlineStatus = 3 | ||
UserOnlineStatusUnavailable UserOnlineStatus = 4 | ||
) | ||
|
||
// UserOnlineStatus represents user online status. | ||
type UserOnlineStatus int64 |