Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ func (h *MockHandler) SelfGet(w http.ResponseWriter, r *http.Request) {
}
}

func (h *MockHandler) HandleActions(w http.ResponseWriter, r *http.Request) {
response := `{
"ok": true
}`

_, err := w.Write([]byte(response))
if err != nil {
h.logger.Fatal("failed to write actions response")
}
}

func (h *MockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch {
case r.FormValue("token") == "":
Expand All @@ -309,6 +320,9 @@ func (h *MockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case r.URL.Path == "/self/get":
h.SelfGet(w, r)
return
case r.URL.Path == "/chats/sendActions":
h.HandleActions(w, r)
return
default:
encoder := json.NewEncoder(w)
err := encoder.Encode(&Response{
Expand Down
5 changes: 5 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (b *Bot) SendChatActions(chatID string, actions ...ChatAction) error {
return b.client.SendChatActions(chatID, actions...)
}

// SendChatNoAction sends an empty action to signal that all actions are done.
func (b *Bot) SendChatNoAction(chatID string) error {
return b.client.SendChatNoAction(chatID)
}

// GetChatAdmins returns chat admins list with fields:
// userID, creator flag
func (b *Bot) GetChatAdmins(chatID string) ([]ChatMember, error) {
Expand Down
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ func (c *Client) SendChatActions(chatID string, actions ...ChatAction) error {
return nil
}

func (c *Client) SendChatNoAction(chatID string) error {
params := url.Values{
"chatId": {chatID},
"actions": {""},
}
_, err := c.Do("/chats/sendActions", params, nil)
if err != nil {
return fmt.Errorf("error while sending no action: %s", err)
}
return nil
}

func (c *Client) GetChatAdmins(chatID string) ([]ChatMember, error) {
params := url.Values{
"chatId": {chatID},
Expand Down
15 changes: 15 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,18 @@ func TestClient_GetInfo_Error(t *testing.T) {

require.NoError(nil)
}

func TestClient_SendChatNoAction(t *testing.T) {
testServer := httptest.NewServer(&MockHandler{})
defer func() { testServer.Close() }()

client := Client{
baseURL: testServer.URL,
token: "test_token",
client: http.DefaultClient,
logger: &logrus.Logger{},
}

err := client.SendChatNoAction("chat_id")
require.NoError(t, err)
}