Skip to content

Commit

Permalink
fix(telegram): ensure proper bot API base (#557)
Browse files Browse the repository at this point in the history
I _think_ that in the refactor in
05a8f0e
the behavior of the base API for Telegram became to use a `/` in between
`bot` and the supplied token.

Per https://core.telegram.org/bots/api#making-requests, the API base
should be:

`https://api.telegram.org/bot<token>/METHOD_NAME`

Note the lack of `/` between `bot` and `<token>`

---------

Co-authored-by: Douglas Reid <doug@steamship.com>
  • Loading branch information
douglas-reid and Douglas Reid committed Sep 26, 2023
1 parent c6c880d commit 8694907
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/steamship/agents/mixins/transports/telegram.py
Expand Up @@ -296,7 +296,7 @@ def get_api_root(self) -> Optional[str]:
# This is a special case for our testing pipeline -- it contains a mock Telegram server.
return api_base
else:
return f"{api_base}{bot_token}"
return f"{api_base[:-1]}{bot_token}"
else:
return None

Expand Down
13 changes: 13 additions & 0 deletions tests/steamship_tests/agents/transports/test_telegram.py
Expand Up @@ -5,6 +5,8 @@
from steamship_tests.utils.deployables import deploy_package

from steamship import File, PackageInstance, Steamship
from steamship.agents.mixins.transports.telegram import TelegramTransport, TelegramTransportConfig
from steamship.agents.service.agent_service import AgentService

config_template = {
"telegram_token": {"type": "string", "default": ""},
Expand All @@ -13,6 +15,17 @@
}


def test_telegram_api_base():
with Steamship.temporary_workspace() as client:
transport = TelegramTransport(
client=client,
agent_service=AgentService(client=client),
config=TelegramTransportConfig(),
)
transport.bot_token = "TOKEN" # noqa: S105
assert transport.get_api_root() == "https://api.telegram.org/botTOKEN"


@pytest.mark.usefixtures("client")
def test_telegram(client: Steamship):

Expand Down

0 comments on commit 8694907

Please sign in to comment.