MCPcopy Index your code
hub / github.com/antirez/botlib / botSendMessageAndGetInfo

Function botSendMessageAndGetInfo

botlib.c:420–455  ·  view source on GitHub ↗

Send a message to the specified channel, optionally as a reply to a * specific message (if reply_to is non zero). * Return 1 on success, 0 on error. */

Source from the content-addressed store, hash-verified

418 * specific message (if reply_to is non zero).
419 * Return 1 on success, 0 on error. */
420int botSendMessageAndGetInfo(int64_t target, sds text, int64_t reply_to, int64_t *chat_id, int64_t *message_id) {
421 char *options[10];
422 int optlen = 4;
423 options[0] = "chat_id";
424 options[1] = sdsfromlonglong(target);
425 options[2] = "text";
426 options[3] = text;
427 options[4] = "parse_mode";
428 options[5] = "Markdown";
429 options[6] = "disable_web_page_preview";
430 options[7] = "true";
431 if (reply_to) {
432 optlen++;
433 options[8] = "reply_to_message_id";
434 options[9] = sdsfromlonglong(reply_to);
435 } else {
436 options[9] = NULL; /* So we can sdsfree it later without problems. */
437 }
438
439 int res;
440 sds body = makeGETBotRequest("sendMessage",&res,options,optlen);
441
442 if (chat_id || message_id) {
443 cJSON *json = cJSON_Parse(body), *res;
444 res = cJSON_Select(json,".result.message_id:n");
445 if (res && message_id) *message_id = (int64_t) res->valuedouble;
446 res = cJSON_Select(json,".result.chat.id:n");
447 if (res && chat_id) *chat_id = (int64_t) res->valuedouble;
448 cJSON_Delete(json);
449 }
450
451 sdsfree(body);
452 sdsfree(options[1]);
453 sdsfree(options[9]);
454 return res;
455}
456
457/* Like botSendMessageWithInfo() but without returning by reference
458 * the chat and message IDs that are only useful if you want to

Callers 2

handleRequestFunction · 0.85
botSendMessageFunction · 0.85

Calls 6

sdsfromlonglongFunction · 0.85
makeGETBotRequestFunction · 0.85
cJSON_ParseFunction · 0.85
cJSON_SelectFunction · 0.85
cJSON_DeleteFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected