Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ jobs:
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

# - uses: Bandwidth/build-notify-slack-action@v1.0.0
# if: always()
# with:
# job-status: ${{ job.status }}
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
# slack-channel: ${{ secrets.SLACK_CHANNEL }}
- uses: Bandwidth/build-notify-slack-action@v2.0.0
if: always()
with:
job-status: ${{ job.status }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ secrets.SLACK_CHANNEL }}

deploy:
name: Deploy `main` to PYPI
Expand Down Expand Up @@ -136,9 +136,9 @@ jobs:
env:
PYPI_API_KEY: ${{ secrets.PYPI_API_KEY }}

# - uses: Bandwidth/build-notify-slack-action@v1.0.0
# if: always()
# with:
# job-status: ${{ job.status }}
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
# slack-channel: ${{ secrets.SLACK_CHANNEL }}
- uses: Bandwidth/build-notify-slack-action@v2.0.0
if: always()
with:
job-status: ${{ job.status }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ secrets.SLACK_CHANNEL }}
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ jobs:
echo "Log level: WARNING"
pytest -v --log-cli-level=WARNING

# - name: Notify Slack of Failures
# uses: Bandwidth/build-notify-slack-action@v2.0.0
# if: failure() && !github.event.pull_request.draft
# with:
# job-status: ${{ job.status }}
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
# slack-channel: ${{ secrets.SLACK_CHANNEL }}
- name: Notify Slack of Failures
uses: Bandwidth/build-notify-slack-action@v2.0.0
if: failure() && !github.event.pull_request.draft
with:
job-status: ${{ job.status }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel: ${{ secrets.SLACK_CHANNEL }}
4 changes: 3 additions & 1 deletion bandwidth/models/bxml/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@copyright Bandwidth INC
"""
import re
from typing import List
import xml.etree.ElementTree as ET

Expand All @@ -14,6 +15,7 @@
class Root:
"""Base class for BXML roots
"""
ssml_regex = r"<([a-zA-Z//].*?)>"

def __init__(self, tag: str, nested_verbs: List[Verb] = None):
"""Initialize instance of class
Expand Down Expand Up @@ -74,4 +76,4 @@ def to_bxml(self) -> str:
str: Serialized BXML string
"""
xml_document = self._generate_xml()
return ET.tostring(xml_document._root, encoding='UTF-8', method='xml', xml_declaration=True).decode("utf8")
return re.sub(self.ssml_regex, r"<\1>", ET.tostring(xml_document._root, encoding='UTF-8', method='xml', xml_declaration=True).decode("utf8"))
1 change: 1 addition & 0 deletions bandwidth/models/bxml/terminal_verb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class TerminalVerb(Verb):
"""Base class for BXML verbs
"""
ssml_regex = r"&lt;([a-zA-Z//].*?)&gt;"

def __init__(self, tag: str, content: str = None):
"""Initialize the verb model
Expand Down
5 changes: 4 additions & 1 deletion bandwidth/models/bxml/verb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@copyright Bandwidth INC
"""
from __future__ import annotations
import re
from typing import Union
import xml.etree.ElementTree as ET

Expand Down Expand Up @@ -107,6 +108,8 @@ def to_bxml(self) -> str:
Returns:
str: Serialized BXML string
"""
ssml_regex = r"&lt;([a-zA-Z//].*?)&gt;"

xml_document = self._generate_xml()
return ET.tostring(xml_document._root).decode('utf8')
# if the root name is speakSentence, replace content with the SSML regex
return re.sub(ssml_regex, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))
6 changes: 2 additions & 4 deletions bandwidth/models/bxml/verbs/speak_sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ def _attributes(self):
"voice": self.voice,
"gender": self.gender,
"locale": self.locale,
}
}

def to_bxml(self) -> str:
SSML_REGEX = r"&lt;([a-zA-Z//].*?)&gt;"

xml_document = self._generate_xml()
return re.sub(SSML_REGEX, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))
return re.sub(self.ssml_regex, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))
2 changes: 1 addition & 1 deletion test/unit/bxml/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def test_to_bxml(self):
assert(expected == self.gather.to_bxml())

def test_add_verb(self):
expected = '<Gather gatherUrl="test.com" gatherMethod="POST" gatherFallbackUrl="fallback-test.com" gatherFallbackMethod="GET" username="user" password="pass" fallbackUsername="user" fallbackPassword="pass" tag="tag" terminatingDigits="2" maxDigits="5" interDigitTimeout="1" firstDigitTimeout="3" repeatCount="2"><PlayAudio username="user" password="pass">https://audio.url/audio1.wav</PlayAudio><SpeakSentence>Hello. Your number is &lt;say-as interpret-as="telephone"&gt;asdf&lt;/say-as&gt;, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Gather>'
expected = '<Gather gatherUrl="test.com" gatherMethod="POST" gatherFallbackUrl="fallback-test.com" gatherFallbackMethod="GET" username="user" password="pass" fallbackUsername="user" fallbackPassword="pass" tag="tag" terminatingDigits="2" maxDigits="5" interDigitTimeout="1" firstDigitTimeout="3" repeatCount="2"><PlayAudio username="user" password="pass">https://audio.url/audio1.wav</PlayAudio><SpeakSentence>Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Gather>'
self.gather.add_verb(self.speak_sentence)
assert(expected == self.gather.to_bxml())
8 changes: 7 additions & 1 deletion test/unit/bxml/test_speak_sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import unittest

from bandwidth.models.bxml import Verb
from bandwidth.models.bxml import SpeakSentence
from bandwidth.models.bxml import SpeakSentence, Response


class TestSpeakSentence(unittest.TestCase):
Expand All @@ -24,3 +24,9 @@ def setUp(self):
def test_to_bxml(self):
expected = '<SpeakSentence voice="julie">Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence>'
assert(expected == self.speak_sentence.to_bxml())

def test_to_bxml_within_response(self):
expected = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<Response><SpeakSentence voice="julie">Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Response>'
response = Response()
response.add_verb(self.speak_sentence)
assert(expected == response.to_bxml())