'Gets the 3pid\'s guest access token if exists, else saves access_token.
Args:
medium (str): Medium of the 3pid. Must be "email".
address (str): 3pid address.
access_token (str): The access token to persist if none is
already persisted.
inviter_user_id (str): User ID of the inviter.
Returns:
deferred str: Whichever access token is persisted at the end
of this function call.'

@defer.inlineCallbacks
def save_or_get_3pid_guest_access_token(self, medium, address, access_token, inviter_user_id):

    def insert(txn):
        txn.execute('INSERT    INTO    threepid_guest_access_tokens    (medium,    address,    guest_access_token,    first_inviter)    VALUES    (?,    ?,    ?,    ?)', (medium, address, access_token, inviter_user_id))
    try:
        (yield self.runInteraction('save_3pid_guest_access_token', insert))
        defer.returnValue(access_token)
    except self.database_engine.module.IntegrityError:
        ret = (yield self.get_3pid_guest_access_token(medium, address))
        defer.returnValue(ret)
