Skip to content

Commit

Permalink
update: direct payment can also have content for bot payment
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Jan 30, 2024
1 parent 49a3c53 commit 36773e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
28 changes: 12 additions & 16 deletions dist/src/controllers/botapi/pay.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/controllers/botapi/pay.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion src/controllers/botapi/pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ import * as socket from '../../utils/socket'
import constants from '../../constants'
import { sphinxLogger } from '../../utils/logger'
import { errMsgString } from '../../utils/errMsgString'
import * as rsa from '../../crypto/rsa'
import { Action, validateAction } from './index'

export default async function pay(a: Action): Promise<void> {
const { amount, bot_name, msg_uuid, reply_uuid, recipient_id, parent_id } = a
const {
amount,
bot_name,
msg_uuid,
reply_uuid,
recipient_id,
parent_id,
content,
} = a

sphinxLogger.info(`=> BOT PAY ${JSON.stringify(a, null, 2)}`)
if (!a.recipient_id) return sphinxLogger.error(`no recipient_id`)
Expand All @@ -19,6 +28,9 @@ export default async function pay(a: Action): Promise<void> {
const tenant: number = owner.id
const alias = bot_name || owner.alias
const botContactId = -1
const encryptedForMeText = rsa.encrypt(owner.contactKey, content || '')
const encryptedText = rsa.encrypt(chat.groupKey, content || '')
const textMap = { chat: encryptedText }

const date = new Date()
date.setMilliseconds(0)
Expand All @@ -37,6 +49,12 @@ export default async function pay(a: Action): Promise<void> {
updatedAt: date,
senderAlias: alias,
tenant,
...(reply_uuid
? {}
: {
messageContent: encryptedForMeText,
remoteMessageContent: JSON.stringify(textMap),
}),
}
if (parent_id) msg.parentId = parent_id
const message: Message = (await models.Message.create(msg)) as Message
Expand Down

0 comments on commit 36773e3

Please sign in to comment.