Skip to content

Commit

Permalink
replybot: upgrade translate-typeform 0.1.0, remove tag from wait
Browse files Browse the repository at this point in the history
  • Loading branch information
nandanrao committed Mar 5, 2023
1 parent c4c7385 commit 598728b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
4 changes: 4 additions & 0 deletions devops/dev-integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kubectl apply -f testing/facebot.yaml
kubectl wait --for=condition=available deployment/gbv-facebot --timeout 5m

envsubst < testing/testrunner.yaml | kubectl apply -f -
2 changes: 1 addition & 1 deletion devops/values/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ chatbaseHost: &host gbv-cockroachdb-public

versionDashboard: &vdashboard v0.0.31
versionBotserver: &vbotserver 0.0.9
versionReplybot: &vreplybot v0.0.140
versionReplybot: &vreplybot v0.0.141
versionLinksniffer: &vlinksniffer v0.0.4
versionDean: &vdean v0.0.25
versionScribble: &vscribble v0.0.23
Expand Down
23 changes: 12 additions & 11 deletions replybot/lib/typewheels/machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ function repeatResponse(question, text) {
}

return {
text,
metadata: JSON.stringify({ repeat: true, ref: question })
message: {
text,
metadata: JSON.stringify({ repeat: true, ref: question })
}
}
}

Expand Down Expand Up @@ -559,15 +561,15 @@ function _gatherResponses(ctx, qa, q, previous = []) {
const f = getField(ctx, md.ref)
f.md = { isRepeat: true }

const repeat = { message: translateField(ctx, qa, f) }
const repeat = translateField(ctx, qa, f)
return [q, repeat]
}

if (md.type === 'statement' || md.keepMoving) {
// if question is statement, recursively
// get the next question and send it too!
const nq = nextQuestion(ctx, qa, md.ref)
if (nq) return _gatherResponses(ctx, qa, { message: nq }, [...previous, q])
if (nq) return _gatherResponses(ctx, qa, nq, [...previous, q])
}

return [...previous, q]
Expand All @@ -576,19 +578,18 @@ function _gatherResponses(ctx, qa, q, previous = []) {
function _response(ctx, qa, { question, validation, response, token, followUp }) {

// if we haven't asked anything, it must be the first question!

if (!question) {
const message = translateField(ctx, qa, ctx.form.fields[0])

if (token) {
return { recipient: { one_time_notif_token: token }, message }
return { recipient: { one_time_notif_token: token }, ...message }
}

return { message }
return message
}

if (followUp) {
return { message: repeatResponse(question, followUpMessage(ctx.form.custom_messages)) }
return repeatResponse(question, followUpMessage(ctx.form.custom_messages))
}

// otherwise, validate the response
Expand All @@ -601,17 +602,17 @@ function _response(ctx, qa, { question, validation, response, token, followUp })

// Note: this could be abstracted to be more flexible
const msg = message || defaultMessage(ctx.form.custom_messages)
return { message: repeatResponse(question, msg) }
return repeatResponse(question, msg)
}

if (token) {
return {
recipient: { one_time_notif_token: token },
message: nextQuestion(ctx, qa, question)
...nextQuestion(ctx, qa, question)
}
}

return { message: nextQuestion(ctx, qa, question) }
return nextQuestion(ctx, qa, question)
}

function respond(ctx, qa, output) {
Expand Down
20 changes: 19 additions & 1 deletion replybot/lib/typewheels/machine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ describe('Machine', () => {

const form = {
logic: [],
fields: [{ type: 'statement', title: 'foo', ref: 'foo', properties: { description: 'type: wait\nwait:\n type: timeout\n value: 25 hours' } },
fields: [{ type: 'statement', title: 'foo', ref: 'foo', properties: { description: '' } },
{ type: 'short_text', title: 'bar', ref: 'bar' }]
}

Expand All @@ -1209,6 +1209,24 @@ describe('Machine', () => {
})


it('sends the messages with an update tag if asked for', () => {

const form = {
logic: [],
fields: [{ type: 'short_text', title: 'bar', ref: 'bar', properties: { description: '{"sendParams": {"tag": "CONFIRMED_EVENT_UPDATE", "messaging_type": "MESSAGE_TAG"}}' } }]
}

const log = [referral]
const action = getMessage(log, form, user)
action.length.should.equal(1)

action[0].messaging_type.should.equal("MESSAGE_TAG")
action[0].tag.should.equal("CONFIRMED_EVENT_UPDATE")
action[0].recipient.id.should.equal('123')
action[0].message.text.should.equal('bar')
})


it('It creates a stitch type message when provided type stitch metadata', () => {

const form = {
Expand Down
2 changes: 1 addition & 1 deletion replybot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@vlab-research/botspine": "0.0.12",
"@vlab-research/chatbase-postgres": "0.0.3",
"@vlab-research/translate-typeform": "^0.0.39",
"@vlab-research/translate-typeform": "^0.1.0",
"@vlab-research/utils": "0.0.11",
"cacheman": "^2.2.1",
"chrono-node": "^1.3.11",
Expand Down

0 comments on commit 598728b

Please sign in to comment.