Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to get USSD response? #34

Open
agn-7 opened this issue Jun 12, 2019 · 0 comments
Open

How to get USSD response? #34

agn-7 opened this issue Jun 12, 2019 · 0 comments

Comments

@agn-7
Copy link

agn-7 commented Jun 12, 2019

How to send a USSD code (i.e. *140*11#) and get its response?

Here is what I have done so far:

import gammu
import unittest


class USSD(unittest.TestCase):
    test_dir = None
    config_name = '/code/config_files/config-smsd.ini'
    dummy_dir = None
    _called = False
    _state_machine = None

    def get_statemachine(self):
        state_machine = gammu.StateMachine()
        state_machine.ReadConfig(Filename=self.config_name)
        state_machine.Init()
        self._state_machine = state_machine
        return state_machine

    def ussd_callback(self, state_machine, response, data):
        """
        Callback on USSD data.
        """
        self._called = True
        self.assertEqual(response, 'USSD')
        self.assertEqual(data['Text'], 'Reply for charge rate')
        self.assertEqual(data['Status'], 'NoActionNeeded')

    def test_ussd(self):
        self._called = False
        state_machine = self.get_statemachine()
        state_machine.SetIncomingCallback(self.ussd_callback)
        state_machine.SetIncomingUSSD()
        state_machine.DialService('*140*11#')
        self.assertTrue(self._called)


if __name__ == '__main__':
    try:
        USSD().test_ussd()
    except KeyboardInterrupt:
        import sys
        sys.exit(0)

Out:

Traceback (most recent call last):
  File "ussd_2.py", line 42, in <module>
    ussd.test_ussd()
  File "ussd_2.py", line 36, in test_ussd
    self.assertTrue(self._called)
  File "/usr/lib/python3.6/unittest/case.py", line 682, in assertTrue
    raise self.failureException(msg)
AssertionError: False is not true

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant