diff --git a/libsplinter.so b/libsplinter.so index 7df6013..9223721 100755 Binary files a/libsplinter.so and b/libsplinter.so differ diff --git a/src/telegram.c b/src/telegram.c index 249107f..12eb720 100644 --- a/src/telegram.c +++ b/src/telegram.c @@ -37,7 +37,19 @@ #include "cmdscript.h" #include "splinter_plugin.h" -#define TG_API "https://api.telegram.org/bot" +/* + * Where the API lives. Overridable, because a gateway you cannot test without + * Telegram is a gateway you only test in production. + */ +static const char * +api_base(void) +{ + const char *env = getenv("SPLINTER_TELEGRAM_API"); + + return env != NULL && *env != '\0' ? env : "https://api.telegram.org"; +} + + #define TG_MAX_CHUNK 3500 #define TG_POLL_S 25 @@ -63,7 +75,7 @@ typing_thread(void *arg) if (sp_buf_init(&url) != 0 || sp_buf_init(&reply) != 0 || sp_buf_init(&err) != 0) return NULL; - sp_buf_printf(&url, "%s%s/sendChatAction", TG_API, t->token); + sp_buf_printf(&url, "%s/bot%s/sendChatAction", api_base(), t->token); { struct sp_buf body; @@ -187,7 +199,7 @@ send_message(const char *token, long chat_id, const char *text, if (sp_buf_init(&url) != 0 || sp_buf_init(&body) != 0 || sp_buf_init(&reply) != 0) return -1; - sp_buf_printf(&url, "%s%s/sendMessage", TG_API, token); + sp_buf_printf(&url, "%s/bot%s/sendMessage", api_base(), token); do { size_t take = len - off; @@ -265,8 +277,8 @@ sp_telegram_run(struct sp_agent *ag, struct sp_host *host, const char *token, int ok; sp_buf_clear(&url); - sp_buf_printf(&url, "%s%s/getUpdates?timeout=%d&offset=%ld", - TG_API, token, TG_POLL_S, offset); + sp_buf_printf(&url, "%s/bot%s/getUpdates?timeout=%d&offset=%ld", + api_base(), token, TG_POLL_S, offset); sp_buf_clear(&reply); if (tg_curl(url.p, NULL, &reply, err) != 0) { fprintf(stderr, "splinter: %s\n",