message: use longer link to describe an article
This commit is contained in:
parent
b74e24da32
commit
12ca31135f
2 changed files with 26 additions and 8 deletions
23
main.mjs
23
main.mjs
|
@ -5,6 +5,7 @@ import {
|
|||
readonlyArray,
|
||||
semigroup,
|
||||
string,
|
||||
taskEither,
|
||||
} from "fp-ts";
|
||||
import { flow, pipe } from "fp-ts/lib/function.js";
|
||||
import { describeArticle } from "./api.mjs";
|
||||
|
@ -35,13 +36,23 @@ bot.on("channel_post", (msg) => {
|
|||
string.trimLeft,
|
||||
),
|
||||
),
|
||||
rte.match(
|
||||
(err) => console.log({ err }),
|
||||
rte.flatMapTaskEither(
|
||||
(res) =>
|
||||
bot.editMessageText(msg.text + "\n\nYandexGPT:\n\n" + res, {
|
||||
chat_id: msg.chat.id,
|
||||
message_id: msg.message_id,
|
||||
}),
|
||||
taskEither.tryCatch(
|
||||
() =>
|
||||
bot.editMessageText(
|
||||
msg.text + "\n\nYandexGpt:\n\n" + res,
|
||||
{
|
||||
chat_id: (msg.forward_from_chat ?? msg.chat).id,
|
||||
message_id: msg.forward_from_message_id ?? msg.message_id,
|
||||
},
|
||||
),
|
||||
String,
|
||||
),
|
||||
),
|
||||
rte.match(
|
||||
(err) => console.log({ err, msg }),
|
||||
(res) => console.log("done", msg.message_id),
|
||||
),
|
||||
)(config)();
|
||||
});
|
||||
|
|
11
message.mjs
11
message.mjs
|
@ -1,4 +1,4 @@
|
|||
import { option, readonlyArray } from "fp-ts";
|
||||
import { number, option, ord, readonlyArray } from "fp-ts";
|
||||
import { flow, pipe } from "fp-ts/lib/function.js";
|
||||
|
||||
const RE_URL =
|
||||
|
@ -13,12 +13,19 @@ const getMessageEntities = (msg) => msg.entities ?? readonlyArray.empty;
|
|||
// isTextLink :: MessageEntity -> boolean
|
||||
const isTextLink = (msgEntity) => msgEntity.type === "text_link";
|
||||
|
||||
const ordStringLength = pipe(
|
||||
number.Ord,
|
||||
ord.contramap((s) => s.length),
|
||||
);
|
||||
|
||||
// getTextLink :: Message -> Option<string>
|
||||
const getTextLink = flow(
|
||||
getMessageEntities,
|
||||
readonlyArray.findFirstMap(
|
||||
readonlyArray.filterMap(
|
||||
flow(option.fromPredicate(isTextLink), option.map((link) => link.url)),
|
||||
),
|
||||
readonlyArray.sort(ordStringLength),
|
||||
readonlyArray.last,
|
||||
);
|
||||
|
||||
export const extractMessageLink = (msg) =>
|
||||
|
|
Reference in a new issue