aboutsummaryrefslogtreecommitdiff
path: root/api/telegram
AgeCommit message (Collapse)Author
11 daysall: apply go fixShulhan
2026-01-03all: use SPDX license header formatShulhan
2024-04-17telegram/bot: register GET endpoint to test webhookShulhan
The call to get "GET <Webhook.URL.Path>/<Token>" will return HTTP status 200 with JSON body '{"code":200,"message":"OK"}'. This endpoint is to check if the bot server is really running.
2024-04-17telegram/bot: move Webhook options initialization to separate methodShulhan
2024-04-17telegram/bot: fix Webhook URL registrationShulhan
Using [path.Join] cause "https://domain" become "https:/domain" which is not a valid URL.
2024-03-15lib/http: refactoring Client methods to return struct ClientResponseShulhan
Instead of returning three variables, [http.Response], []byte, and error, we combine the [http.Response] and []byte into single struct: ClientResponse.
2024-03-14lib/http: refactor Client methods to use struct ClientRequestShulhan
2024-03-09lib/http: refactoring NewServer and NewClientShulhan
The NewServer and NewClient now accept non-pointer options, so the caller unable to modify the options once the server or client has been created.
2024-03-09lib/http: refactor of RegisterEndpoint and RegisterSSE to non-pointerShulhan
Once the endpoint registered, the caller should not able to changes any values on endpoint again.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-02-15all: set unused parameter to "_"Shulhan
2023-09-14all: fix variable shadowing as reported by shadow toolShulhan
The shadow tool [1] report a variable where its name is declared twice or more, in different scope. [1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
2023-09-11api/telegram/bot: realign struct for better size allocationShulhan
The realignment reduce the size of the following struct (in bytes), * Audio: from 112 to 104 (-8) * Bot: from 88 to 72 (-16) * Chat: from 160 to 144 (-16) * Command: from 40 to 32 (-8) * struct in TestCommand_validate: from 72 to 64 (-8) * Contact: from 64 to 56 (-8) * Document: from 80 to 64 (-16) * EncryptedPassportElement: from 144 to 136 (-8) * Game: from 104 to 88 (-16) * InlineKeyboardButton: from 96 to 88 (-8) * InlineQuery: from 64 to 56 (-8) * Message: from 544 to 488 (-56) * MessageEntity: from 64 to 48 (-16) * MessageForward: from 56 to 40 (-16) * messageRequest: from 80 to 56 (-24) * struct in TestMessage_parseCommandArgs: from 576 to 520 (-36) * Options: from 32 to 24 (-8) * OrderInfo: from 56 to 48 (-8) * PassportData: from 64 to 56 (-8) * PreCheckoutQuery: from 88 to 72 (-16) * response: from 56 to 32 (-24) * ShippingQuery: from 48 to 40 (-8) * Sticker: from 136 to 112 (-24) * SuccessfulPayment: from 88 to 80 (-8) * Update: from 96 to 88 (-8) * User: from 64 to 56 (-8) * Venue: from 72 to 56 (-16) * Webhook: from 96 to 72 (-16) * WebhookInfo: from 64 to 40 (-24)
2023-09-11telegram/bot: add missing comment to type MessageForward and UpdateHandlerShulhan
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-01-09lib/http: refactoring NewClient to accept single structShulhan
Previously, the NewClient function accept three parameters: serverURL, http.Header, and insecure. If we want to add another parameter, for example timeout it will cause changes on the function signature. To prevent this changes in the future, we change it now. The NewClient now accept single struct. While at it, we add option to set Timeout. The Timeout affect the http Transport Timeout and TLSHandshakeTimeout. The field is optional, if not set it will set to 10 seconds.
2021-03-14all: refactoring http.Client methods signatureShulhan
Previously, parameters to method Delete, Get, Post, PostForm, PostFormData, PostJSON, Put, and PutJSON are in the following order: (headers, path, params) This is sometimes confusing. To make it better and works with format of HTTP request header, METHOD PATH HEADERS PARAMS we move the path to the first parameter and headers as the second parameter, so the call to client methods would be (path, headers, params)
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2021-03-04http: refactoring parameters on Callback and CallbackErrorHandlerShulhan
Previously, the parameters to Callback has three types: the http.ResponseWriter, *http.Request, and []byte for response body. Not only the type names are long, there is no information on the registered Endpoint on the receiver of Callback. This changes wrap the three parameters into single type EndpointRequest with addition field Endpoint, which contains the registered Endpoint. On the CallbackErrorHandler we also have three parameters, but instead of request body we have an error. This changes store the error for CallbackErrorHandler inside EndpointRequest.Error field.
2020-06-17telegram/bot: changes affected by update on http packageShulhan
2020-06-10all: update email addressShulhan
2020-06-06all: use default linter optionsShulhan
2020-05-29telegram/bot: fix request parameter on GetMyCommandsShulhan
2020-05-28telegram/bot: delete webhook upon setting new webhookShulhan
2020-05-16all: fix and suppress linter warningsShulhan
2020-04-23http: add parameter to set default client's headersShulhan
This changes update the http.Client in api/telegram/bot.
2020-04-12telegram/bot: trim the bot's name when parsing commandShulhan
2020-04-11telegram/bot: fix parsing command and arguments on parseCommandArgsShulhan
2020-04-11api/telegram/bot: Go package for Telegram API BotShulhan