ð² Slack Next-gen platform 㧠Reaction ãã€ãããš DeepL ã§ã¡ãã»ãŒãžã翻蚳ããŠãããã¢ããªãäœã£ãŠã¿ãŸããâïž (EDOCODE Advent Calendar 2022ð)
ïŒãã®èšäºã¯ã| ð EDOCODE Advent Calendar 2022ð | 12æ16æ¥ã®èšäºã§ãïŒðïŒ
ããã«ã¡ã¯ãEDOCODE ã§æ¡çšãæ åœããŠããå±±ç°ã§ãïŒæ¡çšãäž»ãªä»äºã§ãããEDOCODE ã®çµç¹å šè¬ã«è²¬ä»»ãæã£ãŠããŸãã
ä»åã¯ã
- EDOCODE ã®ç€Ÿå ã®æ§åãç¥ã£ãŠãããïŒ
- æè¿ãªãªãŒã¹ããã Slack Next-gen platform ã§ã®ã¢ããªã®äœãæ¹ãç¥ã£ãŠãããïŒ
ããã¿ã«ãAdvent Calendar ã®èšäºãæžããŠããããšæããŸãïŒð
ã€ããã¢ããª
ã¿ã€ãã«ã«ããããšããããReaction ãã€ãããš DeepL ã§ã¡ãã»ãŒãžã翻蚳ããŠãããã¢ããªããäœæããŸãããäŸãã° Slack ã«æ¥æ¬èªã®ã¡ãã»ãŒãžãããããããè±èªã«ç¿»èš³ããŠã»ããå Žåã¯ãæ¥æ¬èªã®å ã¡ãã»ãŒãžã«å°çšã®ãªã¢ã¯ã·ã§ã³ãã€ããŸãããããããšãDeepL 翻蚳ãããè±èªã®ã¡ãã»ãŒãžããã®ãã£ã³ãã«ã«æçš¿ãããŸããå ã¡ãã»ãŒãžãè±èªã®å Žåã¯ãæ¥æ¬èªã®ç¿»èš³ã¡ãã»ãŒãžãæçš¿ãããŸãã
å°ã話ããããŸãããEDOCODE ã§ã¯äºå®ã®ç©ºããŠãã瀟å¡ãã©ã³ãã 㧠4人éžã°ããã©ã³ãäŒãæ¯æ¥è¡ãããŠããŸãããã®ã©ã³ããæœéžããŠããã¢ããªã« "Puff" ãšããååãã€ããŠããã®ã§ãããä»åã®ç¿»èš³ã¢ããªã Puff ã®ãã£ã©ã¯ã¿ãŒã䜿ããã©ã³ãã§ã¯ãªã DeepL 翻蚳ããŠãããæ©èœãæã£ãŠããããšãã "Deep Puff" ãšããååã«ããŠããŸãã
ãã¡ãã®ã¢ã€ã³ã³ã¯çŸè¡ããŒãžã§ã³ã®ãã®ã§ã2幎åã«éçºããŸãããä»åã¯ãSlack ãã 2022幎9æã«Î²ãªãªãŒã¹ ããã "Slack Next-gen platform" ã觊ã£ãŠã¿ãããªãŒãšæã£ãŠããã®ã§ããã®ã¢ããªããŒãããäœãçŽããŠã¿ãŸããã
ã¡ãªã¿ã« Puff ãšããã®ã¯ãPeter Paul & Mary ã®ãPuff, The Magic Dragonããšããæ²ãå ãã¿ã§ãð²ðž
ãªããã®ã¢ããªããããšè¯ãã®ãïŒ
èæ¯
EDOCODE ã«ã¯ 2022幎11æçŸåšã§ 17人ã®ã¡ã³ããŒãåšç±ããŠããŸãããã®ãã¡ãçŽ 35% ã«ããã 6人ãæ¥æ¬èªãã€ãã£ãã§ã¯ãªã人ã§ããã€ãŸã 3åã®1 ã®ã¡ã³ããŒãæ¥æ¬èªãã€ãã£ãã§ã¯ãããŸããããŸããããŸã§ã¯æ¡çšèŠä»¶ã§ãæµæ¢ãªæ¥æ¬èªããå¿ é ã«ããŠããã®ã§ãããåŸã ã«ãã®èŠä»¶ãç·©åããŠããŸããå®éã6人ã®ãã¡çŽè¿ã§å ¥ç€Ÿãã 1人ã¯ããŸã æ¥æ¬èªã§ã®ã³ãã¥ãã±ãŒã·ã§ã³ããšããªãã¡ã³ããŒã§ãã
ããã«æ°èŠãããã¯ãã® PUSHCODE ã§ã¯ãæåãããã°ããŒãã«ãªããŒã ã§ããã°ããŒãã«ã«ãµãŒãã¹ãæäŸãããããšãåæã«ç«ã¡äžããè¡ããŸãããäŒç€Ÿå šäœã "çŽãžã£ãããŒãº" ãªäŒç€Ÿãããå°ãã〠"è±èªãã¬ã³ããªãŒ" ãªäŒç€Ÿãžãšè»¢æããŠããéçšã®äžã«ããŸããããããèæ¯ãããæ¥è±èªã®ç¿»èš³ãå¿ èŠãªå Žé¢ã以åããå¢ããŠããŠããŸããã
äŒç€Ÿãè±èªåããããšã®é£ãã
EDOCODE ã¯ãã£ãšæ¥æ¬èªã§ãã£ãŠããäŒç€Ÿã§ããããããè±èªåããã®ã¯ãªããªãé£ããã§ããã§ãããäŒç€Ÿã®è±èªåã¯äžã®äžã®è¶šå¢ãšããŠåŸ ã£ããªãã§ããããŸããããã§ãããããŠã³ã§è»¢æãæ¥ãããšãããšããã§ãåäœçšãããã®ã¯ç¢ºå®ã«æããŸããããããããããè±èªãã§ããªãåé¡ããããŸããã»ã»ð¥² ãããçããããè±èªãæããŠããã ããŠããæ¯æ¥ã§ãðð»
çµå¶ã¡ã³ããŒãšçžè«ããŠãããããæ¹éã§ãããïŒãšç¹ã«æ±ºããããã§ã¯ãªãã®ã§ãããå°ããã€è±èªã«æµææããªãããããªãæ°ã¥ãããè±èªããªãã身è¿ã«ãªã£ãŠããããšããæèŠãæ¥æ¬èªãã€ãã£ãã®ç€Ÿå¡ã«æã£ãŠãããã®ãè¯ãããããªãããªãŒãšæããããããæ°æã¡ãšçãã§å人çã«ã¯ãã 2幎ã¡ãã£ãšã®éãEDOCODE ã®è±èªåãé²ããŠããŸããã
DeepL ã®ç»å Ž
ã¡ããã©ã³ããçŠãå§ãŸã£ã 2020幎ã®åé ã« DeepL ãæ¥æ¬èªã«å¯Ÿå¿ ããŸãããæ¯ãè¿ã£ãŠã¿ããšããªã¢ãŒãã¯ãŒã¯ç°å¢ãš DeepL ã®ç»å Žã EDOCODE ã®è±èªåã«ãšã£ãŠãšãŠãã¿ã€ãã³ã°è¯ãã£ãæ°ãããŸãããªã¢ãŒãã¯ãŒã¯ã«ãã察é¢ãå£é ã§ã®ã³ãã¥ãã±ãŒã·ã§ã³ãçžå¯Ÿçã«æžããSlack ã Notion ã«ããããã¹ãã³ãã¥ãã±ãŒã·ã§ã³ãå¢ããŸããããããããšãä»®ã«è±èªã§æ å ±ãæµããŠããŠããDeepL ããã°å€§åã®ããšã¯åé¡ãããŸããã
ãã®èŸºãã§ããæ¥æ¬èªã»è±èªã»äžåœèªã§ããã°ãèªåãšçžæãšã®éã§äžçªã³ãã¥ãã±ãŒã·ã§ã³ããããèšèªã§ Slack ããŠãè¯ãã§ããããšç€Ÿå ã«ã¢ããŠã³ã¹ããæ°ãããŸããåããã£ã³ãã«ã«ãã人ã§è±èªãèªããªã人ã§ãããã®äººãéåæçã« DeepL ããã°åé¡ãªãã§ãããäŒç€ŸãšããŠã¯ã³ãã¥ãã±ãŒã·ã§ã³ã³ã¹ããäœããããçç£çãªææçéãããŠããã£ãã»ããè¯ãããã§ãããšã¯èšãããŸã ãã®ææã¯è¡šç«ã£ãŠãããæå³ã§ãé æ ®ãªããããããããšããã瀟å¡ã¯åºãŠããŸããã§ããã
ããããä»ã«ãªã£ãŠæŽ»èºã®æ©äŒãã»ã»ïŒ
çŸè¡ããŒãžã§ã³ãäœæãã 2幎åã¯ãäžèšã®ãããªæãã§ãããè€æ°äººãåå ããŠãããããžã§ã¯ãããšã®ãã£ã³ãã«ã§ã¯ãã¿ããªæ¥æ¬èªã§ãã¹ãããã®ãåºæ¬ã1察1 ã®åå¥ã® DM ã§ã¯äžçªå¿«é©ãªèšèªã§è©±ãããŠãããšèããŠããŸããã§ããäŒç€ŸãšããŠã¯ããã£ãšè±èªãšãäžåœèªãšããã¿ããªãäžçªèªåã®èãããã€ãã£ãã«è¡šçŸã§ããèšèªã§çºä¿¡ããŠè¯ãã§ããããšããã¹ã¿ã³ã¹ã§ããæ®éã«èãããããçæ³ãèšãã®ã¯ç°¡åã ãã©ãå®éãããªããšãããã倧å€ã§ããïŒããšæãã®ãåœããåã§ãã
ã§ãé·ããªããŸããããããããæ°æã¡ãæ®éã ã£ããã¿ããªæã€ã ãããªãããšæããããããªã¢ã¯ã·ã§ã³ãã€ããã ãã§ç¿»èš³ããŠããã Slack ã¢ããªãäœãã°ãåèªã®ç¿»èš³ã«ãããã³ã¹ããå¿ççã³ã¹ããäžããã®ã§ã¯ïŒãšæããDeep Puff ãäœæããã®ã§ãããçµæãšããŠã¯ãã»ãŒèª°ã䜿ã£ãŠãããã« 2幎ãéããŠããŸããð ïŒãã®èšäºãæžãããã«ãã£ã commit log ã調ã¹ãã 2幎åã«éçºããŠããŠã³ã£ããããŸããïŒ
ãããŠçŸåšã¯ãšãããšãäžã§ã觊ããæ¥æ¬èªããŸã ã§ããªãæ°å ¥ç€Ÿå¡ã®ããã«å€§æŽ»èºããŠããŸããEDOCODE ã¯åŽåãŸããã®æ¥åãã°ã«ãŒãäŒç€Ÿã§ãã Wano ã«å§èšããŠããŸãããWano åŽã®åŽåæ åœã®æ¹ã¯è±èªãã§ããŸããããã㧠Deep Puff ãäž¡åã«çŽ¹ä»ããŠãåŽåé¢ä¿ã®ã³ãã¥ãã±ãŒã·ã§ã³ããã£ãŠããã ããŠããŸãããããã®ã¢ããªããªãã£ãããããªã倧å€ã ã£ãã®ã§ã¯ãªãããšæããŸããèªç»èªè³ã§ããã
ïŒâãããªæãã®ãããšããèšèªã®åé¡ãªãããŸãæéããããã«ã§ããŠããŸãðïŒ
Slack Next-gen platform
åå㯠EDOCODE ã®æ§åãã玹ä»ããŸããïŒåŸå㯠Slack ã®æ¬¡äžä»£ãã©ãããã©ãŒã ã§ã®ã¢ããªã®äœãæ¹ãç°¡åã«ã玹ä»ããããšæããŸãðª ãã¶ããã®æã®èšäºã¯ Qiita ã Zenn ãªã©ã®æè¡æ å ±ã¡ãã£ã¢ã§è©³ãã解説ãããŠãããšæããŸãã®ã§ããã®èšäºã§ã¯ãã£ãããšã ã玹ä»ããããšæããŸãã
ç¹åŸŽ
ãã®ãã©ãããã©ãŒã ã®å€§ããªç¹åŸŽã¯ä»¥äžããããšæããŸãã圱é¿åºŠã®é«ãé ã§ã
- Slack ãã€ã³ãã©ãçšæããŠããã
- CLI ãå å®ããŠãã
- Bolt SDK ããããªããäœãããã
- Deno ã§éçºã§ãã
äœãããè¯ããšæããã®ã¯ãSlack ãå®è¡ç°å¢ãçšæããŠããããšããã§ããããããã¡ããã¡ãè¯ãã§ããçŸè¡ã® Deep Puff ãã·ã£ããã«ã©ã³ãããµããŒãããŠãã Puff Lunch 㯠Firebase Functions ã§å®è¡ããŠããŸãããŸãããããã®ããããŸããããªã®ã§äœã£ãŠåãããŸã§ã®ããŒãã«ãããªãäœãã§ãããŸã Slack ã®å€ã§å®è¡ããå ŽåãSlack ã® Trigger ã listen ããããã®ã³ãŒãããæžãå§ããå¿ èŠããããŸããããã£ãšèšãã°ãTrigger ããå Žåã«ã©ã® URL ãžãªã¯ãšã¹ããéãã ãšããèªèšŒãã©ãã ãšãããããããããã¹ãèšå®ãããããããããŸãããð®âðš ãããããã®ãå šãŠãªããªã£ããšããã®ã¯ãããªãç»æçãªæ°ãããŸãã
å°å ¥æé
ãã£ã¡ãç°¡åãªã®ã§ã説æã®å¿ èŠããªããããã§ãããšãã説æãããããããã®ããŒãã§ããð å ¬åŒã®ããŒãžã«ããã€ã³ã¹ãã©ã¯ã·ã§ã³ã©ããã«ãã£ãŠããã°ãäœãåé¡ã¯ãããŸããã以åã¯ãã£ãšå€§å€ã§ããããæ°ãããã©ãããã©ãŒã ã§ã¯ã
- CLI ãã€ã³ã¹ããŒã«ãã
- CLI ã§èªèšŒãéã
- ã³ãã³ã㧠create slack app ãã
- ã³ãã³ã㧠trigger ãäœæãã
- ããŒã«ã«ç°å¢ã§ã¢ããªãèµ·åãã
ã§éçºãéå§ã§ããŸããã¯ãããïŒïŒ
åæ©èœã®çŽ¹ä»
ãŸã£ããåããŠã®æ¹ã«ãšã£ãŠã以äžã®æ©èœãææ¡ããšãã°ã ãããã¢ããªãäœããŸãããšãããã®ãç°¡åã«çŽ¹ä»ããŠãããŸããéçºäžã«ããåç §ãã Slack ã®å ¬åŒããã¥ã¡ã³ãã®ããŒãžãããŒã¹ã«ãŸãšããŠããŸãã
- ã¢ããªã®åããèµ·åããããã£ãããã®éšå
- äœããã£ããã¢ããªã®åŠçãå§ããã®ïŒãšããããšãå®çŸ©ããŸã
- Link, Scheduled, Event, Webhook ã® 4ã€ã®ããªã¬ãŒããããŸã
- ä»åäœã£ã Deep Puff ã¯ããªã¢ã¯ã·ã§ã³ãããããªã®ã§ Event Trigger ã® reaction added ãå©çšããŠããŸã
WorkflowsïŒã¯ãŒã¯ãããŒïŒ
- èµ·åãããã©ããªé çªã§ã©ããªåŠçãããŠããã®ãïŒãå®çŸ©ããŸã
- åŠçã«å¯ŸããŠã®å ¥åã決ããããåŠçãçµãã£ãåŸã®ããŒã¿ãåºåããŠã次ã«æž¡ããããã§ããŸã
- Slack ãžäœãã®åäœãè¡ãããããšãããããã«æžãããšãã§ããŸã
FunctionsïŒé¢æ°ïŒ
- å ·äœçãªåŠçãèšè¿°ããŸã
- é¢æ°ã«ã¯ä»¥äžã«ãã Buit-in Functions ãš Custom Functions ã®ïŒã€ã®ã¿ã€ãããããŸã
Buit-in FunctionsïŒçµã¿èŸŒã¿é¢æ°ïŒ
- Slack ãäºåã«çšæããŠãããŠããé¢æ°ã§ã
- ãã䜿ã Slack ãšé£æºããåŠçãçšæãããŠããŠäŸ¿å©ã§ã
- äŸãã°ãSlack ã«ã¡ãã»ãŒãžãéãããªã©ã¯ Built-in Function ãããã®ã§ããã«å®è£ ã§ããŸã
Custom FunctionsïŒç¬èªé¢æ°ïŒ
- éçºè ç¬èªã®åŠçãå®çŸ©ã§ããŸã
- äŸãã° Slack å€ã®ãµãŒãã¹ãšã®é£æºãæžãããšãã§ããŸã
- Slack ã®åçš® API ãå©çšãã€ã€ãè²ããªåŠçãçµã¿åãããããšããã¡ããå¯èœã§ã
Slack API MethodsïŒSlack API ã®ã¡ãœããïŒ
- ã©ããã£ãŠãã®ãã©ãããã©ãŒã 㧠Slack API ãå©çšããã®ïŒãšãã説æãæžãããŠããŸã
- çŽ æŽãããã®ã¯ãåŸæ¥ã®ããã« Slack API ã䜿ãããã® Token ãªã©ã管çãã€ã€ã³ãŒãã«æžãå¿ èŠããªãããšã§ã
- ãªããªãããã ã«ãããšãã token ãšããåŒæ°ãæž¡ãã ãã§ãã³ã³ããã¹ããšããŠãããå©çšã§ããããã§ã
- ãã㯠Slack ã®ã€ã³ãã©ã§åãããŠãããããªããããšã§ããð
Third-party API CallsïŒå€éš API ã®åŒã³åºãïŒ
- å€éš API ãåŒã¶ã«ã¯ã©ããããè¯ãã®ïŒãšãã説æãæžãããŠããŸã
- èªèšŒæ å ±ã¯ããŒãã³ãŒãã£ã³ã°ããã« .env ã«æžããŠãã³ã³ããã¹ããå©çšããŠäœ¿ã£ãŠãããšç€ºãããŠããŸã
- å ¬åŒã®ãµã³ãã«ã³ãŒã㯠Deno ã® fetch ã§çŽ¹ä»ãããŠããŸãããDeep Puff 㯠Ky ãå©çšããŸãã
Deploy to SlackïŒãããã€ïŒ
- æ¬çªçšã«ãããã€ããéã«ã¯ã¢ããªã®ãã«ããèµ°ããŸã
- ãã®ãšããèªåã§é¢æ°ãå®çŸ©ããŠãããš TypeScript ã®ãã«ããã§ãã¯ãå ¥ããŸã
- èªåã¯æ¥ããããªãã TypeScript ãåããŠã ã£ãã®ã§ããšã©ãŒãèŠãªããå泚éãã€ããŠããã®ã« 2æéããããšãããŠããŸããŸããã»ã»ð
- ãã®ããŒãžèªäœã«ã¯ç¹ã«éèŠãªæ å ±ã¯ãããŸãã
å®éã®ã³ãŒããµã³ãã«
æåŸã«å®éã®ã³ãŒããµã³ãã«ãæ²ç€ºããŠãããŸããèå³ãªã人ã¯ããã§èªã¿çµããŠãã ããïŒ
Triggers
// #/triggers/deep_puff_trigger.ts
import { Trigger } from "deno-slack-api/types.ts";
import DeepPuffWorkflow from "../workflows/deep_puff_workflow.ts";
const deepPuffReactionTrigger: Trigger<typeof DeepPuffWorkflow.definition> = {
type: "event",
name: "Deep Puff Reaction Trigger",
description: "This trigger will run by adding the Deep Puff reaction.",
workflow: "#/workflows/deep_puff_workflow",
event: {
event_type: "slack#/events/reaction_added",
channel_ids: ["xxxxxxxx"],
filter: {
version: 1,
root: {
operator: "OR",
inputs: [{
statement: "{{data.reaction}} == deep-puff"
},
{
statement: "{{data.reaction}} == deep-puff-right"
}],
},
},
},
inputs: {
user_id: {
value: "{{data.user_id}}",
},
message_ts: {
value: "{{data.message_ts}}",
},
channel_id: {
value: "{{data.channel_id}}",
},
},
};
export default deepPuffReactionTrigger;
- Trigger 㯠event ã§ããã® type ã reaction_added ãšå®çŸ©
- filter 㧠:deep-puff: ãŸã㯠:deep-puff-right: ãšãããªã¢ã¯ã·ã§ã³ããã£ããšãã®ã¿ããªã¬ãŒããã
- inputs ã§ã¯ reaction_added ããæž¡ã£ãŠããããŒã¿ã®ãã¡ã©ãã©ããªååã§äœ¿ãã®ããå®çŸ©
Workflows
// #/workflows/deep_puff_workflow.ts
import { DefineWorkflow, Schema } from "deno-slack-sdk/mod.ts";
import { RetrieveMessageFunctionDefinition } from "../functions/retrieve_message_function.ts";
import { DeepLTranslatingFunctionDefinition } from "../functions/deepl_translating_function.ts";
const DeepPuffWorkflow = DefineWorkflow({
callback_id: "deep_puff_workflow",
title: "Deep Puff workflow",
description: "Deep Puff Translating by Adding reaction.",
input_parameters: {
properties: {
user_id: {
type: Schema.slack.types.user_id,
},
message_ts: {
type: Schema.types.string,
},
channel_id: {
type: Schema.slack.types.channel_id,
},
},
required: ["user_id", "message_ts", "channel_id"],
},
});
const retrieveMessageFunctionStep = DeepPuffWorkflow.addStep(
RetrieveMessageFunctionDefinition,
{
channel_id: DeepPuffWorkflow.inputs.channel_id,
message_ts: DeepPuffWorkflow.inputs.message_ts,
},
);
const deepLTranslatingFunctionStep = DeepPuffWorkflow.addStep(
DeepLTranslatingFunctionDefinition,
{
text: retrieveMessageFunctionStep.outputs.message,
},
);
DeepPuffWorkflow.addStep(Schema.slack.functions.SendMessage, {
channel_id: DeepPuffWorkflow.inputs.channel_id,
message: deepLTranslatingFunctionStep.outputs.translated,
});
export default DeepPuffWorkflow;
- DefineWorkflow ã§ã¯å ¥åããŒã¿ã®ããªããŒã·ã§ã³ãå®çŸ©ããŠãã
- å㯠Slack ãçšæããŠãããŠãããã® ã§ã»ãšãã©äºè¶³ããæã
- message_ts ã®å㯠Schema.slack.types.timestamp ã ãšãšã©ãŒã«ãªã£ãŠæåã¡ãã£ãšããã£ã
- ã¯ãŒã¯ãããŒã«ã¯ 3ã€ã®ã¹ããããè¿œå ããŠãã
- (1) ãªã¢ã¯ã·ã§ã³ã® event æ å ±ããã該åœããã¡ãã»ãŒãžãååŸããã¹ãããïŒretrieveMessageFunctionStepïŒ
- (2) ååŸããã¡ãã»ãŒãžã®ããã¹ãã DeepL API ã§ç¿»èš³ããã¹ãããïŒdeepLTranslatingFunctionStepïŒ
- (3) 翻蚳æžã¿ã®ããã¹ãããªã¢ã¯ã·ã§ã³ãã€ããã¡ãã»ãŒãžãšåããã£ã³ãã«ã«ãã¹ãããã¹ãããïŒSchema.slack.functions.SendMessageïŒ
Functions
// #/functions/retrieve_message_function.ts
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import { SlackAPI } from "deno-slack-api/mod.ts";
export const RetrieveMessageFunctionDefinition = DefineFunction({
callback_id: "retrieve_message_function",
title: "Retrieve Messge Function",
description: "Retrieving a message which is added reaction.",
source_file: "functions/retrieve_message_function.ts",
input_parameters: {
properties: {
channel_id: {
type: Schema.slack.types.channel_id,
},
message_ts: {
type: Schema.types.string,
},
},
required: ["channel_id", "message_ts"],
},
output_parameters: {
properties: {
message: {
type: Schema.types.string,
description: "Message to be translated.",
},
},
required: ["message"],
},
});
export default SlackFunction(
RetrieveMessageFunctionDefinition,
async ({ inputs, token }) => {
const client = SlackAPI(token);
const res = await client.conversations.history({
channel: inputs.channel_id,
oldest: inputs.message_ts,
inclusive: true,
limit: 1,
});
if (res.ok) {
const message = res.messages[0].text;
return { outputs: { message } };
} else {
throw "Error: on Slack conversations.history()";
}
},
);
- Slack API methods ã® conversations.history ã䜿ã£ãåŠç
- import { SlackAPI } ããŠãã³ã³ããã¹ãã® { token } ãåŒæ°ã«æž¡ãã ã㧠OK ãªã®ã§ãšãŠã楜
- conversations.history() ã§ã¯ã¿ã€ã ã¹ã¿ã³ãã§æå®ããã¡ãã»ãŒãžãååŸããŠããïŒoldest, inclusive, limitïŒ
// #/functions/deepl_translating_function.ts
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import { SlackAPI } from "deno-slack-api/mod.ts";
import ky from 'https://esm.sh/ky';
export const DeepLTranslatingFunctionDefinition = DefineFunction({
callback_id: "deepl_translationg_function",
title: "DeepL Translating Function",
description: "Translating text via DeepL API.",
source_file: "functions/deepl_translating_function.ts",
input_parameters: {
properties: {
text: {
type: Schema.types.string,
description: "Text to be translated.",
},
},
required: ["text"],
},
output_parameters: {
properties: {
translated: {
type: Schema.types.string,
description: "Message translated.",
},
},
required: ["translated"],
},
});
const translate = async (source: string, authKey: string, targetLang = "JA") => {
const host = 'api.deepl.com';
const v = 'v2';
const type = 'translate';
const url = 'https://' + host + '/' + v + '/' + type;
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: "DeepL-Auth-Key " + authKey,
};
const text = source.replace(/<@\w+>/g, "");
const searchParams = { text, target_lang: targetLang };
interface Translation { detected_source_language: string, text: string }
interface DeepLResponse { translations: Translation[] }
const res: DeepLResponse = await ky.post(url, { headers, searchParams }).json();
let translated: string = res.translations[0].text;
if (res.translations[0].detected_source_language === targetLang) {
translated = await translate(source, authKey, "EN");
}
return translated;
}
export default SlackFunction(
DeepLTranslatingFunctionDefinition,
async ({ inputs, env }) => {
const source = inputs.text;
const authKey = env.DEEPL_AUTH_KEY;
const translated = await translate(source, authKey);
return { outputs: { translated } };
},
);
- HTTP ã¯ã©ã€ã³ãã«ã¯ Ky ã䜿ã£ã
- DeepL API ã¯ å ¬åŒã®ããã¥ã¡ã³ã ãåç §
- å©çšã¯ææã®ã¢ã«ãŠã³ããå¿ èŠã§ãïŒðµ
- ç¬èªã«å®çŸ©ããŠãã translate() ã¯ãããã€æã« TypeScript ã®ãã§ãã¯ãå ¥ããããå泚éãåæã«è¿œå ããŠãã
- const text = source.replace(/<@\w+>/g, ""); 㯠DeepL ã«æž¡ã翻蚳å ããã¹ããã Slack ã®ãŠãŒã¶ãŒ ID ãªã©ã®è±æ°åãåé€ããŠãã
- 翻蚳ã¯ãæ¥æ¬èªã ã£ããè±èªãè±èªã ã£ããæ¥æ¬èªã«ç¿»èš³ããããšããã®ãã¢ããªã®èŠä»¶
- DeepL 㯠API ã®ã¬ã¹ãã³ã¹ã§å ¥åããããã¹ãã®èšèªå€å®ãè¿ã£ãŠãã
- ãããèŠãŠããã翻蚳å ããã¹ããæ¥æ¬èªã ã£ãå Žåã¯ã翻蚳å èšèªïŒtargetLangïŒãè±èªã«æå®ããŠå床ãªã¯ãšã¹ããæãçŽããŠããïŒå®è£ ãšããŠã¯ååž°ããŠããïŒ
- DeepL API ã®èªèšŒæ å ±ã¯ .env ã«ä¿ç®¡ã㊠{ env } ã®ã³ã³ããã¹ãããåŒã³åºããŠãã
- Firebase Functions ã®çŸè¡ããŒãžã§ã³ã ãšã.env ãããã«ã NPM ããã±ãŒãžãå¿ èŠã ã£ãã®ã§ãæ¬åœã«ãããããð
ãŸãšã
ãšããããšã§ãEDOCODE ã®ã¡ãã£ãšããæåãšãããããµããŒãããããã®ããŒã«ãäœã£ã話ãã玹ä»ããŸããïŒð
人äºã®æ åœè ãããããç°¡åãªããã°ã©ãã³ã°ãã§ãããšãçµç¹ãã¿ãŒã§ãããããã®æ¬²ããïŒããšãªã£ããšãã«ãããšã€ãã£ãŠç€Ÿå ã«æäŸã§ããã®ã§äŸ¿å©ã ãªãšæããŸããæ®éã®äŒç€Ÿã ãšãšã³ãžãã¢ã¯äºæ¥ããŸããéšçœ²ã«ãããããã®ã§ããããããã®ã¯æå¿ã®ãšã³ãžãã¢ã空ãæéã«ã€ãã£ãŠãããã®ãæåŸ ãããããé¡ããããããããšãå€ãã®ããªãšãSlack Next-gen platform ã«ãããããã«ã°ããšããã°ã©ãã³ã°ã®èŠæ±ã¬ãã«ãäžãã£ãã®ã§ããããæ©ã«éãšã³ãžãã¢ãããã¯ãªãã£ã¹ã®æ åœè ãã©ãã©ãå¿ èŠãªã·ãŒã³ã§ã¢ããªãã€ãã£ãŠãããã®ã§ã¯ãªãããšæããŸãïŒð
çŸè¡ããŒãžã§ã³ã§ã¯éçºã« 2, 3æ¥ã¯ããã£ããšæããŸãããä»åã®ãªãã¥ãŒã¢ã«ã§ã¯éçºç°å¢ã®åŠç¿ãå«ããŠåèš 12æéãããããããããªãã£ããšæããŸããããããã€ã³ããçµæ§ãã£ããã®ã®ãããããã¯ãªã¢ããã°ãã¡ããã¡ãç°¡åã«å®è£ ã§ããŠããŸãã®ã§ãæ¬åœã«äŸ¿å©ã ãšæããŸãïŒä»ããã§ãããããã£ããã€ã³ãã解説ããã¹ãã§ããïŒïŒïŒãã¶ãããããèšäºãããã°ãã£ãšæ©ãéçºã§ããŠãã
æ°ããããŒãžã§ã³ã®ã¢ããªã¢ã€ã³ã³ã§ãðð Figma ã§é©åœã«ããã·ã¥ã¢ããããŠäœããŸããðšâð³
ãç¥ãã
EDOCODE ã§ã¯ããšã³ãžãã¢ã»ãã¶ã€ããŒã»ãããã¯ããããžã£ãŒãåéããŠããŸãïŒïŒïŒð
ãèå³ã®ããæ¹ã¯ã
ããããã² Wantedly ã§ã話ãèãã«è¡ããããððð ããŠãã ããïŒ
ãŸã EDOCODE ã®æ¡çšããŒãžããããŸãã®ã§ããã¡ãããã²ã芧ãã ããð
https://go.edocode.co.jp/jobs