|
| 1 | +/* |
| 2 | +activation_example:!d20 I try to jump over a 10 foot gap |
| 3 | +regex:!d20 |
| 4 | +flags:gmi |
| 5 | +*/ |
| 6 | + |
| 7 | +(function(current) { |
| 8 | + |
| 9 | + var prompt = current.text.replace(/!d20/gmi, "").trim().substring(0, 1000); |
| 10 | + var chatReq = new sn_ws.RESTMessageV2(); |
| 11 | + chatReq.setEndpoint('https://api.openai.com/v1/chat/completions'); |
| 12 | + chatReq.setHttpMethod("POST"); |
| 13 | + chatReq.setRequestHeader("Authorization", "Bearer " + gs.getProperty("openai.key")); |
| 14 | + chatReq.setRequestHeader('Content-Type', "application/json"); |
| 15 | + chatReq.setRequestHeader('User-Agent', "ServiceNow"); |
| 16 | + chatReq.setRequestHeader("Accept", "*/*"); |
| 17 | + var body = { |
| 18 | + "model": "gpt-4o", |
| 19 | + "messages": [{ |
| 20 | + "role": "system", |
| 21 | + "content": ` |
| 22 | + You are a Slack bot that enhances the formatting of messages to make them more engaging and visually appealing. |
| 23 | + Utilize Slack's markdown language mrkdwn for various formatting elements. |
| 24 | + Follow these instructions: |
| 25 | + 1. Enclose important words or phrases with *asterisks* for bold emphasis. |
| 26 | + 2. Enclose code and numbers and percentages using backticks, like \`this\`. |
| 27 | + 3. Use emojis when necessary to add expressiveness. |
| 28 | + 4. Organize text with numbered or bullet lists, using "-" for bullet points. |
| 29 | + 5. Combine bold and lists as needed: *Bold text*: normal text. |
| 30 | + 6. Italicize words like _this_. |
| 31 | + 7. Use blockquotes with ">" for quotes. |
| 32 | + 8. For URLs, use <http://example.com|Clickable link>. |
| 33 | + 9. Keep user (@user) and channel (#channel) tags unchanged. |
| 34 | + Keep close to the original message tone and formatting.` |
| 35 | + }, |
| 36 | + { |
| 37 | + "role": "user", |
| 38 | + "content": "You are a dungeon master and a player is about to roll a D20 to determine the outcome of an action they are pursuing. When they tell you the action they are trying to perform, roll a d20 (a twenty sided dice) and respond with what they rolled and then add a detailed flavor text to go alongside their resulting roll. If they roll a critical failure (a 1) or a critical success (a 20), the flavor text should be incredibly exaggerated to emphasize the extreme luck. Try to make non-critical rolls still interesting but reflective of the number rolled still. Here is what your player is trying to do, in their words: " + prompt |
| 39 | + } |
| 40 | + ], |
| 41 | + }; |
| 42 | + chatReq.setRequestBody(JSON.stringify(body)); |
| 43 | + var chatResponse = chatReq.execute(); |
| 44 | + gs.info(chatResponse.getBody()); |
| 45 | + var chatResponseBody = JSON.parse(chatResponse.getBody()); |
| 46 | + |
| 47 | + var intro = "> " + prompt + "\n"; |
| 48 | + new x_snc_slackerbot.Slacker().send_chat(current, intro + "\n" + chatResponseBody.choices[0].message.content, false); |
| 49 | +})(current); |
0 commit comments