#include #include #include #include #include bool run = true; void sighandler(int signum) { run = false; } void echo_message(tgbot_s *bot, tgbot_update_s *update) { tgbot_send_message(bot, update->chat_id, update->text, "MARKDOWN", NULL); } int main(void) { /* Retrieve bot's token */ FILE *fp = fopen(".token", "r"); if (fp == NULL) { fprintf(stderr, "Unable to retrieve bot token\n"); return 1; } char token[256]; fscanf(fp, "%s", token); fprintf(stdout, "Token: %s\n", token); fclose(fp); signal(SIGINT, sighandler); /* Initialize bot */ tgbot_s *bot = tgbot_new(token); tgbot_update_s update; while (run) { tgbot_get_update(bot, &update, NULL); if (strcmp(update.text, "/start") == 0) { /* Send dice if /start otherwise echo the message */ tgbot_send_dice(bot, update.chat_id, NULL); } else { echo_message(bot, &update); } } fprintf(stdout, "Closing..."); tgbot_free(bot); return 0; }