Created
May 11, 2018 18:47
-
-
Save xenogenesi/3cfecc5ed4676c2cfaab717483bc5457 to your computer and use it in GitHub Desktop.
fix meinside/telegram-bot-go's EditMessageText response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/methods.go b/methods.go | |
index 55a6eca..7c997a7 100644 | |
--- a/methods.go | |
+++ b/methods.go | |
@@ -723,7 +723,7 @@ func (b *Bot) AnswerCallbackQuery(callbackQueryID string, options map[string]int | |
// other options: parse_mode, disable_web_page_preview, and reply_markup | |
// | |
// https://core.telegram.org/bots/api#editmessagetext | |
-func (b *Bot) EditMessageText(text string, options map[string]interface{}) (result APIResponseMessage) { | |
+func (b *Bot) EditMessageText(text string, options map[string]interface{}) (result APIResponseBool) { | |
// essential params | |
params := map[string]interface{}{ | |
"text": text, | |
@@ -735,7 +735,7 @@ func (b *Bot) EditMessageText(text string, options map[string]interface{}) (resu | |
} | |
} | |
- return b.requestResponseMessage("editMessageText", params) | |
+ return b.requestResponseBool("editMessageText", params) | |
} | |
// EditMessageCaption edits caption of a message | |
@@ -1411,6 +1411,27 @@ func (b *Bot) requestResponseInt(method string, params map[string]interface{}) ( | |
return APIResponseInt{APIResponseBase: APIResponseBase{Ok: false, Description: &errStr}} | |
} | |
+// Send request for APIResponseBool and fetch its result. | |
+func (b *Bot) requestResponseBool(method string, params map[string]interface{}) (result APIResponseBool) { | |
+ var errStr string | |
+ | |
+ if bytes, err := b.request(method, params); err == nil { | |
+ var jsonResponse APIResponseBool | |
+ err := json.Unmarshal(bytes, &jsonResponse) | |
+ if err == nil { | |
+ return jsonResponse | |
+ } | |
+ | |
+ errStr = fmt.Sprintf("json parse error: %s (%s)", err, string(bytes)) | |
+ } else { | |
+ errStr = fmt.Sprintf("%s failed with error: %s", method, err) | |
+ } | |
+ | |
+ b.error(errStr) | |
+ | |
+ return APIResponseBool{APIResponseBase: APIResponseBase{Ok: false, Description: &errStr}} | |
+} | |
+ | |
// Send request for APIResponseString and fetch its result. | |
func (b *Bot) requestResponseString(method string, params map[string]interface{}) (result APIResponseString) { | |
var errStr string | |
diff --git a/types.go b/types.go | |
index 01ccf93..96b9f29 100644 | |
--- a/types.go | |
+++ b/types.go | |
@@ -196,6 +196,12 @@ type APIResponseInt struct { | |
Result int `json:"result,omitempty"` | |
} | |
+// APIResponseBool is an API response with result type: bool | |
+type APIResponseBool struct { | |
+ APIResponseBase | |
+ Result bool `json:"result,omitempty"` | |
+} | |
+ | |
// APIResponseString is an API response with result type: string | |
type APIResponseString struct { | |
APIResponseBase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment