Skip to content

Commit

Permalink
merged master & remove sensitive data
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ome committed Oct 25, 2019
2 parents 2384051 + 45b2856 commit 770b469
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
31 changes: 31 additions & 0 deletions fixture/vcr_cassettes/pin_chat_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"request": {
"body": "chat_id=666&message_id=666",
"headers": [],
"method": "post",
"options": {
"recv_timeout": 10000
},
"request_body": "",
"url": "https://api.telegram.org/bot<TOKEN>/pinChatMessage"
},
"response": {
"binary": false,
"body": "{\"ok\":true,\"result\":true}",
"headers": {
"Server": "nginx/1.16.1",
"Date": "Wed, 02 Oct 2019 15:48:04 GMT",
"Content-Type": "application/json",
"Content-Length": "25",
"Connection": "keep-alive",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Expose-Headers": "Content-Length,Content-Type,Date,Server,Connection"
},
"status_code": 200,
"type": "ok"
}
}
]
31 changes: 31 additions & 0 deletions fixture/vcr_cassettes/unpin_chat_message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"request": {
"body": "chat_id=666",
"headers": [],
"method": "post",
"options": {
"recv_timeout": 10000
},
"request_body": "",
"url": "https://api.telegram.org/bot<TOKEN>/unpinChatMessage"
},
"response": {
"binary": false,
"body": "{\"ok\":true,\"result\":true}",
"headers": {
"Server": "nginx/1.16.1",
"Date": "Wed, 02 Oct 2019 15:49:52 GMT",
"Content-Type": "application/json",
"Content-Length": "25",
"Connection": "keep-alive",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Expose-Headers": "Content-Length,Content-Type,Date,Server,Connection"
},
"status_code": 200,
"type": "ok"
}
}
]
34 changes: 34 additions & 0 deletions lib/nadia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,38 @@ defmodule Nadia do
def delete_sticker_from_set(sticker) do
request("deleteStickerFromSet", sticker: sticker)
end

@doc """
Use this method to pin a message in a group, a supergroup, or a channel. The bot must be an
administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right
in the supergroup or ‘can_edit_messages’ admin right in the channel. Returns True on success.
Args:
* `chat_id` - Unique identifier for the target chat or username of the target channel
(in the format @channelusername)
* `message_id` - Identifier of a message to pin
Options:
* `disable_notification` - Pass True, if it is not necessary to send a notification to all
chat members about the new pinned message. Notifications are always disabled in channels.
"""
@spec pin_chat_message(integer | binary, integer | binary, [{atom, any}]) ::
:ok | {:error, Error.t()}
def pin_chat_message(chat_id, message_id, options \\ []) do
request("pinChatMessage", [chat_id: chat_id, message_id: message_id] ++ options)
end

@doc """
Use this method to unpin a message in a group, a supergroup, or a channel. The bot must be an
administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in
the supergroup or ‘can_edit_messages’ admin right in the channel. Returns True on success.
Args:
* `chat_id` - Unique identifier for the target chat or username of the target channel
(in the format @channelusername)
"""
@spec unpin_chat_message(integer | binary) :: :ok | {:error, Error.t()}
def unpin_chat_message(chat_id) do
request("unpinChatMessage", chat_id: chat_id)
end
end
14 changes: 13 additions & 1 deletion test/nadia_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,22 @@ defmodule NadiaTest do
test "send_animation" do
use_cassette "send_animation" do
file_id = "BQADBAADhQEAArKi5FCHKeOFAAEsKQkWBA"
{:ok, message} = Nadia.send_animation(-261_856_796, file_id)
{:ok, message} = Nadia.send_animation(666, file_id)

assert is_map(message.document)
assert message.document.file_id == file_id
end
end

test "pin_chat_message" do
use_cassette "pin_chat_message" do
assert :ok = Nadia.pin_chat_message(666, 666)
end
end

test "unpin_chat_message" do
use_cassette "unpin_chat_message" do
assert :ok = Nadia.unpin_chat_message(666)
end
end
end

0 comments on commit 770b469

Please sign in to comment.